SerializerGroups and ParserGroups
Above the serializers and parsers are the {@link oaj.serializer.SerializerGroup} and
{@link oaj.parser.ParserGroup} classes.
These classes allow serializers and parsers to be retrieved by W3C-compliant HTTP Accept
and Content-Type values...
// Construct a new serializer group with configuration parameters that get applied to all serializers.
SerializerGroup group = SerializerGroup.create()
.append(JsonSerializer.class, UrlEncodingSerializer.class);
.ws() // or .useWhitespace(true)
.swaps(TemporalCalendarSwap.IsoLocalDateTime.class)
.build();
// Find the appropriate serializer by Accept type and serialize our POJO to the specified writer.
group.getSerializer("text/invalid, text/json;q=0.8, text/*;q:0.6, *\/*;q=0.0")
.serialize(myPerson, myWriter);
// Construct a new parser group with configuration parameters that get applied to all parsers.
ParserGroup group = ParserGroup.create()
.append(JsonSerializer.class, UrlEncodingSerializer.class);
.swaps(CalendarSwap.IsoLocalDateTime.class)
.build();
Person myPerson = group.getParser("text/json").parse(myReader, Person.class);
The REST servlet API builds upon the SerializerGroup and ParserGroup classes
to provide annotated REST servlets that automatically negotiate the HTTP media types and allow the developer
to work with requests and responses as POJOs.