{title:'SerializerSets and ParserSets', updated:'9.0.0'}

On top of the serializers and parsers are the {@link oaj.serializer.SerializerSet} and {@link oaj.parser.ParserSet} classes. These classes allow serializers and parsers to be grouped and retrieved by W3C-compliant HTTP Accept and Content-Type values...

| // Construct a new serializer group with configuration parameters that get applied | // to all serializers. | SerializerSet serializers = SerializerSet.create() | .add(JsonSerializer.class, UrlEncodingSerializer.class) | .forEach(x -> x.swaps(TemporalCalendarSwap.IsoLocalDateTime.class)) | .forEachWS(x -> x.ws()) // or .useWhitespace(true) | .build(); | | // Find the appropriate serializer by Accept type and serialize our POJO to the | // specified writer. | serializers | .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. | ParserSet parsers = ParserSet.create() | .add(JsonSerializer.class, UrlEncodingSerializer.class) | .forEach(x -> x.swaps(CalendarSwap.IsoLocalDateTime.class)) | .build(); | | Person myPerson = parsers | .getParser("text/json") | .parse(myReader, Person.class);

The REST servlet API builds upon the SerializerSet and ParserSet 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.