{updated} Configurable Properties

As shown in previous sections, Juneau serializers and parsers are highly-configurable through properties. (See {@doc ConfigurableProperties})

These properties can be defined for serializers and parsers registered on a REST resource via the following:

- {@link oajr.annotation.RestResource#properties() RestResource(properties)}
- {@link oajr.RestContextBuilder} - Various methods on the context builder.

##### Example:

import static org.apache.juneau.BeanContext.*; import static org.apache.juneau.serializer.Serializer.*; import static org.apache.juneau.json.JsonSerializer.*; // Servlet with properties applied @RestResource( properties={ // Bean properties should be sorted alphabetically. @Property(name=BEAN_sortProperties, value="true"), // Nulls should not be serialized @Property(name=SERIALIZER_trimNulls, value="true"), // Solidus characters should be escaped in JSON @Property(name=JSON_escapeSolidus, value="true") } ) public MyRestServlet extends BasicRestServlet {...}

The programmatic equivalent to this is:

// Servlet with properties applied @RestResource(...) public MyRestServlet extends BasicRestServlet { public MyRestServlet(RestContextBuilder builder) { builder .sortProperties(); // Note: RestContextBuilder extends from BeanContextBuilder .set(SERIALIZER_trimNulls, true); .set(JSON_escapeSolidus, true); } }

Properties can also be overridden at the Java method level:

- {@link oajr.annotation.RestMethod#properties() RestMethod(properties)}
- {@link oajr.RequestProperties}

// GET method with method-level properties @RestMethod( name=GET, path="/*", properties={ // Bean properties should be sorted alphabetically. @Property(name=BEAN_sortProperties, value="true"), // Nulls should not be serialized @Property(name=SERIALIZER_trimNulls, value="true"), // Solidus characters should be escaped in JSON @Property(name=JSON_escapeSolidus, value="true") } public Object doGet() { ... }

##### See Also:

- {@link oajr.annotation.RestResource#flags() RestResource(flags)} - Shorthand for boolean properties.
- {@link oajr.annotation.RestMethod#flags() RestMethod(flags)} - Shorthand for boolean properties.
- {@link oajr.RestContextProperties}
- {@link oajr.RestMethodProperties}