Hello all,
I'm using the Jackson json library to work with some Json/Xml content,
the content type is dynamic. My feature needs to open the payload, remove
some data and generate a new version. The problem I'm getting is the way
Jackson is handling the root element name for xml content. Follows one
example that works and one that don't.
*Prints different, but I wanted it to be equal*
ObjectMapper xmlMapper = new XmlMapper();
String original = "<user><name>jhon</name><age>28</age></user>";
String expected = "<user><name>jhon</name></user>";
ObjectNode obj = xmlMapper.readValue(original, ObjectNode.class);
obj.remove("age");
String serialized = xmlMapper.writeValueAsString(obj);
if (expected.equals(serialized)) {
System.out.println("Equals");
} else {
System.out.println("Different");
}
*Print equals as expected*
ObjectMapper jsonMapper = new ObjectMapper();
String original = "{\"name\":\"Joe\",\"age\":28}";
String expected = "{\"name\":\"Joe\"}";
ObjectNode obj = jsonMapper.readValue(original, ObjectNode.class);
obj.remove("age");
String serialized = jsonMapper.writeValueAsString(obj);
if (expected.equals(serialized)) {
System.out.println("Equals");
} else {
System.out.println("Different");
}
The gist contains the full example code
https://gist.github.com/diegooliveira/34252ae174cfee4e52628ecfc962aaf1. Are
there any way that this code might work properly?
Thanks in advance,
D.
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.