I have a JSON property file, which is updated by a user manually.
I am mapping it to objects, using Jackson Object mapper:
[
{ "id":"01",
"name":"Joe",
"Children" : [ {"Name" : "Alex",
"Age" : "21"},
{"name" : "David",
"Age" : "1"}
]
},
{ "id":"02",
"name":"Jackson",
"Children" : [ {"Name" : "Mercy",
"Age" : "10"},
{"name" : "Mary",
"Age" : "21"}
]
}
]
Since it is updated manually by a user, they can use any casing; mixed, upper, lower, etc. The solution I have found is, while reading the file I am converting to lower case, like this :
String content = new Scanner(new File("filename")).useDelimiter("\\Z").next();
After this I am mapping to my object using Jackson, which works. I am using lower case member names for the mapped classes. Is it the right approach or is there any other way?
You can use
ObjectMapper mapper = new ObjectMapper();
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
This feature is in Jackson version 2.5.0 onwards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With