Open jlouvel opened 11 years ago
For those running into this:
My current solution is to create a ConverterService
subclass that calls JacksonRepresentation.setObjectMapper
, JacksonRepresentation.setObjectReader
and JacksonRepresentation.setObjectWriter
with pre-configured (reused) versions.
I think the main hurdle to solve this in the restlet code base is that the JacksonRepresentation.createObjectMapper
method create a different ObjectMapper
per MediaType
, which makes it hard to reuse it.
For an alternative that doesn't involve subclassing ConverterService
(but does involve subclassing JacksonConverter
), check out this example from nearly six (!) years ago:
https://github.com/Tembrel/restlet-misc
That example is in the context of dependency injection, but the basic idea of subclassing JacksonConverter
and registering the subclass with the Restlet engine can be applied anywhere.
We should facilitate the reuse of expensive objects such as ObjectMapper.
See this discussion thread: http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3044375
Some references: http://wiki.fasterxml.com/JacksonBestPracticesPerformance https://github.com/Tembrel/restlet-misc/blob/master/src/main/java/net/peierls/restlet/misc/LocalJacksonConverter.java