My java pojo looks like this
public class myPersonTO{
String name;
String surname;
Map<String, Double> categories;
}
I am using the gson library, however I an not sure what my json stringn, and the object it is created from should like; I am using json stringify, on a javascript object containing two strings and an array of objects, see 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); //convert json object, then use in submit
and then in Java I am usign the following :
Type listType = new TypeToken<List<myPersonTO>>() {}.getType();
List<myPersonTO> myPersonTOList = new Gson().fromJson(jsonString,listType);
Any help gratefully received. Cheers !
Your question isn’t very clear, but I think the JSON verson of one of those objects would look like:
edit — OK in response to the extensive changes in your question: your “categories” object should not be an array. It should be a plain object, as in my example. Well, at least that’s what I’d imagine it should be. I’d have to check this “gson” thing to make sure, but I’d be kind-of surprised to learn that it wants Java Map instances to be represented as arrays (surprised to the extent that I’d find another library).