I have the following JSON String extracted fro MongoDB:
{ "_id" : { "$oid" : "552645a5d3d57a6fc594c3c6"} , "name" : "mark" ,
"Info" : { "age" : 18 , "email" : "[email protected]" , "phone" : "321-456-778"}}
I'm trying to map the above JSON to the following class:
public class User {
String name;
Info info;
// Getters/Setters
public User(String name, int age, String email, String phone) {
this.name = name;
this.info = new Info(age, email, phone);
}
static class Info{
public Info(int age, String email, String phone) {
super();
this.email = email;
this.phone = phone;
this.age = age;
}
public Info( ) {
}
String email;
String phone;
int age;
// Getters/Setters
}
}
By using the fromJson method of Gson:
Gson gson = new Gson();
User u = gson.fromJson(jsonString, User.class);
The resulting User has a null Info attached to it. Any idea how to fix it?