what's the difference with the two objectmappers. databind.ObjectMapper&map.ObjectMapper

2,124 views
Skip to first unread message

Eone Zhang

unread,
Jun 6, 2014, 9:01:53 AM6/6/14
to jackso...@googlegroups.com
what's the difference with the two objectmappers.
com.fasterxml.jackson.databind.ObjectMapper
org.codehaus.jackson.map.ObjectMapper


I configured the org.codehaus.jackson.map.ObjectMapper mapper like this;
    mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
    mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.getSerializationConfig().setSerializationInclusion(Inclusion.NON_NULL);

but how can I achieve the same result with the new Mapper(com.fasterxml.jackson.databind.ObjectMapper),
now I configured the new mapper like this:
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);

is there an alternative way to config  ALLOW_SINGLE_QUOTES and Inclusion.NON_NULL options for the mapper of com.fasterxml.jackson.databind.ObjectMapper

I want to use com.fasterxml.jackson.databind.ObjectMapper because of the data-bind api, but I still want to be compatible the program that use org.codehaus.jackson.map.ObjectMapper. the client can send json string without quotes(such as {username:'',password:''})



Tatu Saloranta

unread,
Jun 6, 2014, 2:26:24 PM6/6/14
to jackso...@googlegroups.com
One is from Jackson version 2.0 or above (com.fasterxml one); the the other for earlier 1.x version (1.9 or earlier). They live in different Java packages, and you can not mix pieces of 1.x with those of 2.x (specifically, annotations are also in different packages). Make sure to also include `jackson-core` version that matches.

Feature ALLOW_SINGLE_QUOTES should still be available with 2.x; just make sure you have matching 2.x version of jackson-core and jackson-databind.

Inclusion is also available; method to call is `ObjectMapper.setSerializationInclusion()`.

Hope this helps,

-+ Tatu +-



--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages