Upgrading to Jackson 2.0 from 1.9 in Jersey not working

ぐ巨炮叔叔 提交于 2019-11-30 20:13:05

I'm answering my own question, based on the (useful) answers from StaxMan and pgelinas.

I had to do two things to make it work.

The first things was to remove the com.sun.jersey.api.json.POJOMappingFeature from my web.xml.

The second was to update my jackson-jaxrs-json-provider (actually, all of my Jackson artifacts) to 2.1.

With 2.1 or 2.0, and POJOMappingFeature, Jackson 1.9 was still being used for serialization.

With 2.0, and POJOMappingFeature removed, I got a missing message body writer error.

With 2.1 and POJOMappingFeature removed, everything worked as expected.

It is not enough to simply upgrade Jackson core and mapper versions; integration between Jersey (or any JAX-RS implementation) and Jackson happens using specific JAX-RS provider. For Jackson, this would be https://github.com/FasterXML/jackson-jaxrs-json-provider.

So you also need to add 2.x Jackson JAX-RS JSON provider, and that will make Jersey use Jackson 2.x for its operation.

I would double-check if you don't have both versions of Jackson in your classpath. The package names in Jackson 2.x got changed to com.fasterxml from org.codehaus. This way you don't have some cryptic classpath problem (like a NoClassDefFound), but if you don't use the proper packages this is the kind of behavior that you'll see.

Also, the annotations were extracted into their own project, jackson-annotations.

even if you upgrade to jackson 2 you will have NoClassfound error as spring using old jackson.

Check spring implementation on this link: http://git.springsource.org/sandbox/cbeams/blobs/4731d671cbeb82b87dd0f10e16cd09d8f267b433/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/json/MappingJacksonJsonView.java

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