I'm using jackson
to serialize my object as json. I'm using 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 the put
method with JsonNode
overload is deprecated.Why following overload of put
method is deprecated:
public JsonNode put(String fieldName, JsonNode value);
What is the alternative for that?
Also I tried this:
String jsonStr = mapper.writeValueAsString(appVersion);
resNode.put("status", true);
resNode.put("appObject", jsonStr);
But this method puts double quote ("
) around appObject
value as a string value.
They added a new method for these actions. ObjectNode.put(String, JsonNode)
Try instead resNode.set("appObject", appObject);
.
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