we are working on java rest web service we are using the below 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
Using the above jars below code is working fine in tomcat server.
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(Inclusion.NON_NULL);
String userJsonString = mapper.writeValueAsString(userJSON);
JSONObject userJsonObj = new JSONObject(userJsonString);
While deploying this in WAS server we have got the below error:
Error 500: javax.servlet.ServletException: java.lang.NoSuchMethodError: org/codehaus/jackson/map/ObjectMapper.setSerializationInclusion(Lorg/codehaus/jackson/map/annotate/JsonSerialize$Inclusion;)Lorg/codehaus/jackson/map/ObjectMapper;
From the jars it looks like you are using codehaus jackson: https://github.com/codehaus/jackson/ instead of fasterxml jackson: https://github.com/FasterXML/jackson. With codehaus jackson your code will look like:
objectMapper.getSerializationConfig().setSerializationInclusion(Inclusion.NON_NULL)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With