Reputation: 1313
Using GSON :
Gson gson = new Gson();
String json = gson.toJson(response);
System.out.println(json);
I receive the following JSON representation of a User:
"{\"userID\":\"user2\",\"firstName\":\"Maria\",\"lastName\":\"Silva\",\"birthDate\":\"Ago 1, 2012\",\"gender\":\"Female\"}"
Now, I want to get those values to construct a User object (doing User.setuserID, userObj.setFirstName, ... )
How can I get the correspond values to set the User values?
Upvotes: 0
Views: 60
Reputation: 45070
Gson
will do that for you. You need not worry about it. That's the power of Gson
.
User object = gson.fromJson(jsonString, User.class); // Fully populated User object.
Upvotes: 1