MoienGK
MoienGK

Reputation: 4654

How to make json jackson faster?

this line of code takes about 2 seconds to execute!

ObjectMapper mapper = new ObjectMapper();

since two seconds is a life time when it comes to computing, is there any way to make jackson respond faster?

i am using :

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.13</version>
    </dependency>

Upvotes: 1

Views: 3997

Answers (1)

user2046264
user2046264

Reputation:

The version of Jackson you are using is an older version, consider upgrading to Jackson 2.0. There may be a bit of efforts involved (depends on what APIs you are using), but any new features and performance enhancements will likely to be 2.x only. Have a look at Jackson Release: 2.0 for more information and upgrade notes.

As for ObjectMapper, this is what Jackson Best Practices: Performance says:

ObjectMapper: object mappers cache serializers and deserializers that are created first time handler is needed for given type (or more precisely, mapper holds a reference to Provider objects that do). If you do not reuse mappers, new serializers and deserializers need to be created each time: and these are expensive operations due to amount of introspection and annotation processing involved.

What is the platform you are running on, mobile perhaps? On my 3+ year old laptop creating an instance takes less than half a second.

If performance is a concern and your JSON is not too complex, consider using Jackson's streaming API (that's the real power of Jackson) to parse the JSON data yourself, it will be an order of magnitude faster.

Upvotes: 1

Related Questions