I have a JsonNode with this JSON in it :
{"temperature":17,"long":200,"lat":100}
I want to change the JsonNode to look like this
{"MyNewFieldName":17,"long":200,"lat":100}
Is it possible using Jackson API ?
You won't be able to rename keys in key-value JSON pairs. What you will need to do is create a new key-value pair with the same value but with a different key and remove the old one.
JsonNode node = ...;
ObjectNode object = (ObjectNode) node;
object.set("MyNewFieldName", node.get("temperature"));
object.remove("temperature");
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