Here is the structure of my Java POJO:
public class MyPersonTO{
String name;
String surname;
Map<String, Double> categories;
}
Currently, I am using the Gson library, but I'm uncertain about the formatting of my JSON string and the object it should be created from. I am using `JSON.stringify` on a JavaScript object that has two strings and an array of objects. Here is a simplified version in pseudo code:
var json = [];
jsonObject = new Object();
jsonObject.name = "testname"
jsonObject.surname = "testsurname"
var categories = [];
for(index=0; index < 10; index++){
var category = new Object();
category.key = getKey();
category.value = index;
categories.push(category);
}
jsonObject.categories = categories;
json.push(jsonObject);
json = JSON.stringify(json); //converts JSON object for submission
In my Java code, I am using the following:
Type listType = new TypeToken<List<MyPersonTO>>() {}.getType();
List<MyPersonTO> myPersonList = new Gson().fromJson(jsonString, listType);
If you have any advice or suggestions on this matter, please feel free to share. Thank you!