Skip to content

JSON Serialization

DuyHai DOAN edited this page May 5, 2013 · 15 revisions

Default configuration

Internally, Achilles stores data in JSON format using the Jackson Mapper library. JSON serialization is way faster than the old plain Object serialization since only data are serialized, not class structure.

By default, Achilles sets up an internal Object Mapper with the following feature config:

  1. Serialization Inclusion = NON NULL
  2. Deserialization FAIL_ON_UNKNOWN_PROPERTIES = false
  3. JacksonAnnotationIntrospector + JaxbAnnotationIntrospector

Jackson will serialize all your entities even if they do not have any JSON annotations. You can also use JAXB annotations.


## Custom Object Mapper

It is possible to inject a pre-configured Jackson Object Mapper as configuration parameter to bootstrap the ThriftEntityManagerFactory class using the "achilles.json.object.mapper" parameter.

Map<String,Object> configMap = new HashMap<String,Object>();
configMap.put("achilles.json.object.mapper", preConfiguredObjectMapper);

...

ThriftEntityManagerFactory emf = new ThriftEntityManagerFactory(configMap);

## Custom Object Mapper Factory

Last but not least, it is possible to further custom JSON serialization using the ObjectMapperFactory interface using the "achilles.json.object.mapper.factory" parameter:

public interface ObjectMapperFactory
{
	public <T> ObjectMapper getMapper(Class<T> type);
} 


Map<String,Object> configMap = new HashMap<String,Object>();
configMap.put("achilles.json.object.mapper.factory", customObjectMapperFactoryImpl);

...

ThriftEntityManagerFactory emf = new ThriftEntityManagerFactory(configMap);

When both "achilles.json.object.mapper.factory" and "achilles.json.object.mapper" params are provided for configuration, Achilles will ignore the "achilles.json.object.mapper" param and only use the "achilles.json.object.mapper.factory" one

Home

Clone this wiki locally