【问题标题】:org/codehaus/jackson/map/ObjectMapper.setSerializationInclusion exception in WAS serverWAS 服务器中的 org/codehaus/jackson/map/ObjectMapper.setSerializationInclusion 异常
【发布时间】:2013-11-01 14:45:18
【问题描述】:

我们正在开发 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

使用上面的 jars 下面的代码在 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;

【问题讨论】:

    标签: java json rest jersey


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      可能是杰克逊版本冲突。检查 WAS 在其类路径(库)中是否包含 Jackson jar

      【讨论】:

      • 这在我的经验中相当普遍,尤其是在 2.x 和 1.x 版本之间。
      • OK。我们已经在类路径IBM/WebSphere/AppServer/Lib.am I rite?中搜索了?
      • 我没用过WAS。在 IBM/WebSphere 的所有子目录中搜索。还要检查您的应用程序存档(war 或 ear)是否没有重复的 Jackson jar。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多