Class UonSerializer

All Implemented Interfaces:
AnnotationProvider, HttpPartSerializer, UonMetaProvider
Direct Known Subclasses:
OpenApiSerializer, UonSerializer.Encoding, UonSerializer.Readable, UrlEncodingSerializer

Serializes POJO models to UON (a notation for URL-encoded query parameter values).
Media types

Handles Accept types: text/uon

Produces Content-Type types: text/uon

Description

This serializer provides several serialization options. Typically, one of the predefined DEFAULT serializers will be sufficient. However, custom serializers can be constructed to fine-tune behavior.

The following shows a sample object defined in Javascript:

{ id: 1, name: 'John Smith', uri: 'http://sample/addressBook/person/1', addressBookUri: 'http://sample/addressBook', birthDate: '1946-08-12T00:00:00Z', otherIds: null, addresses: [ { uri: 'http://sample/addressBook/address/1', personUri: 'http://sample/addressBook/person/1', id: 1, street: '100 Main Street', city: 'Anywhereville', state: 'NY', zip: 12345, isCurrent: true, } ] }

Using the "strict" syntax defined in this document, the equivalent UON notation would be as follows:

( id=1, name='John+Smith', uri=http://sample/addressBook/person/1, addressBookUri=http://sample/addressBook, birthDate=1946-08-12T00:00:00Z, otherIds=null, addresses=@( ( uri=http://sample/addressBook/address/1, personUri=http://sample/addressBook/person/1, id=1, street='100+Main+Street', city=Anywhereville, state=NY, zip=12345, isCurrent=true ) ) )

Example:

// Serialize a Map Map map = JsonMap.ofJson("{a:'b',c:1,d:false,e:['f',1,false],g:{h:'i'}}"); // Serialize to value equivalent to JSON. // Produces "(a=b,c=1,d=false,e=@(f,1,false),g=(h=i))" String uon = UonSerializer.DEFAULT.serialize(map); // Serialize a bean public class Person { public Person(String name); public String getName(); public int getAge(); public Address getAddress(); public boolean deceased; } public class Address { public String getStreet(); public String getCity(); public String getState(); public int getZip(); } Person person = new Person("John Doe", 23, "123 Main St", "Anywhere", "NY", 12345, false); // Produces "(name='John Doe',age=23,address=(street='123 Main St',city=Anywhere,state=NY,zip=12345),deceased=false)" String uon = UonSerializer.DEFAULT.serialize(person);

Notes:
  • This class is thread safe and reusable.
See Also: