I use jacksonto serialize my object as json. I am using the following code:
ObjectMapper mapper = new ObjectMapper();
JsonNodeFactory nodeFactory = new JsonNodeFactory(false);
ObjectNode resNode = new ObjectNode(nodeFactory);
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(ApplicationVersion.class, new SingleApplicationSerializer());
mapper.registerModule(simpleModule);
JsonNode appObject = mapper.valueToTree(appVersion);
resNode.put("status", true);
resNode.put("appObject", appObject); //This put method is deprecated.
But I saw that the putoverload method is JsonNodeout of date. Why after method overloading is putdeprecated:
public JsonNode put(String fieldName, JsonNode value);
What is the alternative for this?
Also I tried this:
String jsonStr = mapper.writeValueAsString(appVersion);
resNode.put("status", true);
resNode.put("appObject", jsonStr);
But this method puts a double quote ( ") around the value appObjectas a string value.
source
share