Jackson 2.0 with Jersey 1.12

為{幸葍}努か 提交于 2019-12-10 08:24:56

问题


Has anybody managed to use jackson 2.0 with Jersey 1.12. It will be very interesting to know. We have to use jackson 1.9.x all over the place, just because jersey has jackson so strongly coupled. From what I see even jersey 2.0M3 is still using jackson 1.9.2. So it seems there is no point to wait for jersey team to do it in near future.


回答1:


Custom provider works; and "official" Jackson 2.0 JSON provider project does the same, with bit more features (ability to use @JsonView annotation and a few others on resource methods).

This is one of nice things with JAX-RS: everything is modular, and adding new improved providers is very easy.




回答2:


I've Jackson 2.0 and Jersey 1.12 in my project. I had not any problems with it, but probably reason is that I had custom Provider with some additional ObjectMapper settings. Simplified version:

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;

import com.fasterxml.jackson.databind.ObjectMapper;

@Provider
public class ObjectMapperProvider implements ContextResolver<ObjectMapper> {

    private final ObjectMapper defaultObjectMapper;

    public ObjectMapperProvider() {
        defaultObjectMapper = new ObjectMapper();
    }

    @Override
    public ObjectMapper getContext(Class<?> type) {
        return defaultObjectMapper;
    }
}



回答3:


If you're trying to use JsonView with Jersey, you must use org.codehaus.jackson.map.annotate.JsonView if you use the method 2.2 on here: http://wiki.fasterxml.com/JacksonFAQJaxRs

If you want to use JsonView from com.fasterxml, you must use the general method (1) on that page.



来源:https://stackoverflow.com/questions/10668597/jackson-2-0-with-jersey-1-12

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!