tags:

views:

36

answers:

1

ObjectMapper in Jackson seem to be thread safe. http://wiki.fasterxml.com/JacksonFAQThreadSafety

Does this mean, is it OK for me to declare

class Me {
    private static final ObjectMapper mapper = new ObjectMapper();
}

instead of

class Me {
    private final ObjectMapper mapper = new ObjectMapper();
}

Thanks.

+1  A: 

Yes, that is safe and recommended.

The only caveat from the page you refererred is that you can't be modifying configuration of the mapper once it is shared; but you are not changing configuration so that is fine. If you did need to change configuration, you would do that from the static block and it would be fine as well.

StaxMan
Do you have any reference source?
Yan Cheng CHEOK
Opps. I realize you are the developer of Jackson. Thanks for the great software! I compare it against JSONObject and gjson, and found Jackson meet my need.
Yan Cheng CHEOK
Hey no problem -- glad to hear this
StaxMan