3

我们正在开发 java rest web 服务,我们正在使用下面的 jars

jackson-mapper-asl-1.9.2.jar
jackson-jaxrs-1.9.2.jar
jackson-core-asl-1.9.2.jar
jackson-xc-1.9.2.jar
org.json-20120521.jar

使用上面的代码下面的 jar 在 tomcat 服务器中工作正常。

ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Inclusion.NON_NULL);
String userJsonString = mapper.writeValueAsString(userJSON);
JSONObject userJsonObj = new JSONObject(userJsonString);

在 WAS 服务器中部署它时,我们收到以下错误:

Error 500: javax.servlet.ServletException: java.lang.NoSuchMethodError: org/codehaus/jackson/map/ObjectMapper.setSerializationInclusion(Lorg/codehaus/jackson/map/annotate/JsonSerialize$Inclusion&#59;)Lorg/codehaus/jackson/map/ObjectMapper&#59;
4

2 回答 2

2

从 jars 看起来你正在使用 codehaus jackson: https://github.com/codehaus/jackson/而不是 fasterxml jackson: https://github.com/FasterXML/jackson。使用 codehaus jackson,您的代码将如下所示: objectMapper.getSerializationConfig().setSerializationInclusion(Inclusion.NON_NULL)

于 2017-04-26T21:59:46.290 回答
0

It may be Jackson versions collision. Check if WAS contains Jackson jars in its classpath (libraries)

于 2013-10-23T10:58:51.340 回答