New question. I am trying to deserialize a JSON f...
# spring
l
New question. I am trying to deserialize a JSON file into an object tree, using ObjectMapper. So far so good. However, the schema of the JSON file is inconsistent. Sometimes a property is a string, other times an array. Sometimes it’s a boolean, other times it’s a nested object. I can make some changes to the schema, but I cannot really redesign it. I’ve already managed to merge the string/array case by forcing it to always be an array, but I don’t know what to do with for bool/object case. Any suggestions?
a
I typically de-serialize to a LinkedHashMap and then parse to an Object tree by hand. It's ugly, but it works
c
a few options, all along the lines of accepting a range of cases and normalizing them: 1. Write custom deserializers that can take, for example “0”, “1", true, “true” etc for a boolean, and any other combinations; 2. Deserialize to a Map or a JsonNode tree and start normalizing from there; at this point you can either regenerate now-normalized JSON and bind that to objects, or create the objects by hand as an extension of the normalization (as noted above)