views:

46

answers:

1

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 !

A: 
Pointy
gson is googles library for handling json objects, its part of guava.
NimChimpsky
Yes thanks, I found it - I was not able to determine from the "user guide" whether maps are encoded as arrays of key/value pairs. I'd still be surprised to learn that they are.
Pointy
they may well not - still getting my head around json formatting. thnx for your help.
NimChimpsky