restlet / restlet-framework-java

The first REST API framework for Java
https://restlet.talend.com
647 stars 284 forks source link

Optimize Jackson extension performance #715

Open jlouvel opened 11 years ago

jlouvel commented 11 years ago

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

qsiebers commented 5 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.

Tembrel commented 5 years ago

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.

qsiebers commented 5 years ago

@Tembrel Yes, I've applied that approach before here.