Skip to main content

URL-Encoding Parsers

The UrlEncodingParser class is used to parse URL-Encoding into POJOs.

When to use it​

Use UrlEncodingParser to read a query string or form body, such as name='John+Smith'&age=45, into a bean or map. It reverses UrlEncodingSerializer and decodes the URL escapes for you.

Example​

import org.apache.juneau.marshall.urlencoding.*;

public class UrlEncodingParserExample {

public static class Person {
public String name;
public int age;
}

public static void main(String[] args) throws Exception {
Person person = UrlEncodingParser.DEFAULT.read("name='John+Smith'&age=45", Person.class);

System.out.println(person.name + " " + person.age);
}
}

Options​

The following pre-configured parsers are provided for convenience:

InstanceAccepts
UrlEncodingParser.DEFAULTapplication/x-www-form-urlencoded text with UON-style values.

For anything else, start from the builder's create() method. The settings readers reach for first:

Builder methodEffect
expandedParams()Treat repeated name=value pairs as the elements of one collection.
validateEnd()Fail if anything but whitespace follows the parsed value.
trimStrings()Trim whitespace from parsed string values.
autoCloseStreams()Close the input stream or reader when parsing finishes.
beanDictionary(Class...)Classes the parser may instantiate from _type properties.
swaps(Class...)Object swaps that convert parsed values into other types.

The class hierarchy for the builder of this parser is below. Refer to the builder javadocs for the full set of configurable settings.

Context.BuilderMarshallingContextable.BuilderParser.BuilderReaderParser.BuilderUonParser.BuilderUrlEncodingParser.Builder

See also​