I am working with a web application which accepts json object, parses it and create a User object. I want to give this json input in gson.fromJson(jsonData, User.class);:
{
users:[{
name: "Jack",
email: "email1",
friends:[{
name: "name2",
email: "email2",
}]
}]
}
what should i do to give this json object in place of jsonData. I am working with google app engine.
Thanks in advance.
If you use Gson, please read doc here.
As
jsonDatayou can pass string with your json or Reader which streams your json data.UPD: In your case you need to deserialize array, so use it as
GSon uses reflections to set properties, so make sure you have setters for all properties in json, like
User.setName,User.setEmail,User.setFriends, ..