Transforms
The Juneau serializers and parsers can be configured on how to handle POJOs through the use of Transforms.
(See {@doc juneau-marshall.Transforms Transforms})
Transforms are associated serializers and parsers registered on a REST resource via the following:
- {@link oaj.annotation.BeanConfig#beanFilters() BeanConfig(beanFilters)} - On class or methods.
- {@link oaj.annotation.BeanConfig#pojoSwaps() BeanConfig(pojoSwaps)} - On class or methods.
- {@link oajr.RestContextBuilder#beanFilters(Object...)}
- {@link oajr.RestContextBuilder#pojoSwaps(Object...)}
// Servlet with transforms applied
@Rest(
...
)
@BeanConfig(
pojoSwaps={
// Calendars should be serialized/parsed as ISO8601 date-time strings
TemporalCalendarSwap.IsoInstant.class,
// Byte arrays should be serialized/parsed as BASE64-encoded strings
ByteArraySwap.Base64.class
},
beanFilters={
// Subclasses of MyInterface will be treated as MyInterface objects.
// Bean properties not defined on that interface will be ignored.
MyInterface.class
}
)
public MyRestServlet extends BasicRestServlet {...}
The programmatic equivalent to this is:
// Servlet with properties applied
@Rest(...)
public MyRestServlet extends BasicRestServlet {
public MyRestServlet(RestContextBuilder builder) {
builder
.pojoSwaps(
TemporalCalendarSwap.IsoInstant.class,
ByteArraySwap.Base64.class
)
.beanFilters(MyInterface.class);
}
}