It's much better to re-use a single ObjectMapper instance, or a small set of 
differently configured ObjectMapper instances.

Here's an example of using dependency injection to provide a single 
ObjectMapper that is then re-used by JacksonRepresentations created by a JSON 
converter:

https://github.com/Tembrel/restlet-misc/blob/master/src/main/java/net/peierls/restlet/misc/LocalJacksonConverter.java

You can use the same approach in your resources by injecting a singleton 
ObjectMapper into your resources (see, for example, 
http://tembrel.blogspot.com/2012/03/restlet-guice-extension-considered.html) 
and using a custom extension of JacksonRepresentation that uses that 
ObjectMapper.

Note that I'm using Jackson 2.x with a Restlet Jackson extension that works 
with Jackson 1.9, which is why my extension of JacksonRepresentation doesn't 
simply override createObjectMapper().

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3044414

Reply via email to