Flattening means to put the JSON Object into a single-Hierarchy-level like structure also called flat structure i.e there are no child or parent objects, everything is a key-value pair. Nested Objects will be accessible by dot operator. On the contrary Un-flattening means to put the flattened structure in to Mutli-level structure where there exists Parent-child structure.
You need to pass a un-flattened structure to Object-mapper to de-serialize it.
Following examples will help in understanding it better
Nested JSON Object
{ "a":
{ "b": 1,
"c": null,
"d": [false, true]
},
"e": "f",
"g": 2.3
}
Flattened JSON
{ "a.b": 1,
"a.c": null,
"a.d[0]": false,
"a.d[1]": true,
"e": "f",
"g": 2.3
}
Java Map like flattened JSON
{a.b=1, a.c=null, a.d[0]=false, a.d[1]=true, e=f, g=2.3}
Why flattening is required? If you don't internal structure of JSON Object, it will be quite cumbersome to access all the elements inside hence simple solution is to put everything on the same level and deepness of Objects is depicted by dot operator. So flattening makes it easier to access the internal elements.
Serialization and de-serialization can only happen on un-flattened JSONs.
Found this repository(https://github.com/wnameless/json-flattener) to flatten and unflatten a json. Make sure you unflatten it to a String first before feeding it to ObjectMapper. Unfortunately did not find a specification that defined the differences.