Class UrlEncodingSerializer

All Implemented Interfaces:
AnnotationProvider, HttpPartSerializer, UonMetaProvider, UrlEncodingMetaProvider
Direct Known Subclasses:
UrlEncodingSerializer.Expanded, UrlEncodingSerializer.PlainText, UrlEncodingSerializer.Readable

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

Handles Accept types: application/x-www-form-urlencoded

Produces Content-Type types: application/x-www-form-urlencoded

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 URL-encoded 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 uenc = UrlEncodingSerializer.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 uenc = UrlEncodingSerializer.DEFAULT.serialize(person);

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