Is there a way to deserialize the following xml into Map holding List of items using Jackson?
12345678
<
The other answers don't work if you have to use readTree()
and JsonNode
. I know it's an ugly solution but at least you don't need to paste someone's gist in your project.
Add org.json to your project dependencies.
And then do the following:
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONObject;
import org.json.XML;
...
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
...
JSONObject soapDatainJsonObject = XML.toJSONObject(data);
return OBJECT_MAPPER.readTree(soapDatainJsonObject.toString());
The conversion goes as follows:
XML -> JSONObject (using org.json) -> string -> JsonNode (using readTree)
Of course, toJSONObject handles duplicates without any problems, I suggest to avoid using Jackson and readTree()
if you can.