I have a json request which hits a post mapping call
{ "xyz":"tyu",
"abc":"test1=1&test2=2&.....test100=100"
}
There are 100+ key value pairs in the field abc. How do I map it to a java class which contains these 100+ fields
My approach:
@PostMapping("/employee")
public Response someMethod(@RequestBody Employee emp) {
String reqStream = emp.getAbc();
String[] reqStreamArray = reqStream.split("&");
for (String pair : reqStreamArray) {
String[] reqStreamKeyValue = pair.split("=");
String key = reqStreamKeyValue[0];
String value = reqStreamKeyValue[1];
switch (key) {
case "test1":
emp.setTest1(value);
break;
So the problem is I need to have 100+ switch stmts which is wrong. What is the better approach?