The RequestBody entity Person in a POST request has a map as following
class Person {
String name;
int age;
Map<String, String> otherProperties;
}
The above entity is mapped via RequestBody as following:
public void processInput(@RequestBody Person person) {
}
Though the invoker of this API sends following JSON in the input:
{
"name": "nameOfPerson",
"age": 10,
"otherProperties": {
"key1": "val1",
"key2": "val2",
"key3": "val3"
}
}
the spring controller processes it as :
{
"name": "nameOfPerson",
"age": 10,
"otherProperties": {
"key2": "val2",
"key3": "val3",
"key1": "val1",
}
}
The order of the map inside the entity is not maintained.
How to make sure the Spring controller reads and processes the map in the right order as was being sent by the invoker?
LinkedHashMap implementation or other implementation of Map does not guarantee that the input order be maintained.