Announcement Announcement Module
Collapse
No announcement yet.
Incompatibility of MappingJacksonHttpMessageConverter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Incompatibility of MappingJacksonHttpMessageConverter

    The class
    Code:
    org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
    from Spring 3.2.1 version is now incompatible to Jackson FasterXML 2.1.x versions. I found following incompatibilities:

    1. Incorrect imports. Current Spring implementation uses following imports:

    Code:
    import org.codehaus.jackson.JsonEncoding;
    import org.codehaus.jackson.JsonGenerator;
    import org.codehaus.jackson.JsonProcessingException;
    import org.codehaus.jackson.map.ObjectMapper;
    import org.codehaus.jackson.map.SerializationConfig;
    import org.codehaus.jackson.map.type.TypeFactory;
    import org.codehaus.jackson.type.JavaType;
    Whereas, as per new Jackson FasterXML library, these should be:
    Code:
    import com.fasterxml.jackson.core.JsonEncoding;
    import com.fasterxml.jackson.core.JsonGenerator;
    import com.fasterxml.jackson.core.JsonProcessingException;
    import com.fasterxml.jackson.databind.JavaType;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import com.fasterxml.jackson.databind.SerializationFeature;
    import com.fasterxml.jackson.databind.type.TypeFactory;
    2. Following method is using a method which is removed from Jackson library.
    Code:
    protected JavaType getJavaType(Type type, Class<?> contextClass) {
       return (contextClass != null) ? 
        TypeFactory.type(type, TypeFactory.type(contextClass)) :
                        TypeFactory.type(type);
    }
    In the new Jackson FasterXML 2.1.3 version, the method
    Code:
    TypeFactory.type
    is removed. Instead of this, following should be used:
    Code:
    protected JavaType getJavaType(Type type, Class<?> contextClass) {
       final TypeFactory typeFactory = this.objectMapper.getTypeFactory();
       return (contextClass != null) ? typeFactory.constructType(type, contextClass) : typeFactory.constructType(type);
    }
    3. Spring code is using enums which are removed from Jackson library. e.g.

    SerializationConfig.Feature.INDENT_OUTPUT is replaced by
    SerializationFeature.INDENT_OUTPUT

    4. Spring code is using deprecated method to create JSON factory in the method writeInternal.

    Code:
    JsonGenerator jsonGenerator = this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);
    The method getJsonFactory() is deprecated and the new method is getFactory()

    My question is, will Spring fix these in its library or I should write my own message converter.

    Thanks,
    NN

  • #2
    Following class should be used to use Jackson 2.x APIs.

    Code:
    org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
    With this, this thread should be marked complete.

    Thanks,
    NN

    Comment

    Working...
    X