Skip to main content

UON Parsers

The UonParser class is used to parse UON into POJOs.

When to use it​

Use UonParser to read UON text, such as a header value or a URL parameter that UonSerializer wrote, back into POJOs. If the text arrives URL-encoded (%20 for a space), use the decoding instance so the escapes are resolved first.

Example​

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

public class UonParserExample {

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

public static void main(String[] args) throws Exception {
// Plain UON.
Person a = UonParser.DEFAULT.read("(name='John Smith',age=45)", Person.class);

// UON whose characters are URL-encoded.
Person b = UonParser.DEFAULT_DECODING.read("(name='John%20Smith',age=45)", Person.class);

System.out.println(a.name + " " + a.age + ", " + b.name + " " + b.age);
}
}

Options​

The following pre-configured parsers are provided for convenience:

InstanceAccepts
UonParser.DEFAULTPlain UON text.
UonParser.DEFAULT_DECODINGUON text with URL-encoded characters, decoded before parsing.

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

Builder methodEffect
decoding()URL-decode the input before parsing.
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.Builder

See also​