3

I have the following string:

{"account":{
    "username":"ikevin2222",
    "birthdate":"2017-01-31T09:37:44.000Z",
    "gender":true,
    "emailaddresses": [{
        "emailaddress":"aaa@bbb.com",
        "verificationcode":"AAAAAA",
        "isverified":false
    }]
}}

How do I use Google/GSON to convert it to Java POJO?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
ikevin8me
  • 4,253
  • 5
  • 44
  • 84

1 Answers1

7

Generate your POJO by using http://www.jsonschema2pojo.org/ or by adding plugin in studio (https://github.com/Hexara/Json2Pojo)

now add dependencies compile 'com.google.code.gson:gson:2.6.2':

convert your json or string to POJO

Gson gson = new Gson();
POJOClass pojo = gson.fromJson(jsonObject.toString(), new TypeToken<POJOClass>() {}.getType());
Rajesh
  • 2,618
  • 19
  • 25