0

I have little strange query here.

I have a sample JSON.

"properties": {
"emailID": {
  "type": "string"
},
"createdDate": {
  "type": "date"
},
"lastModifiedDate": {
  "type": "date"
}

}

I am using GSON here to parse. And I understand I will have to write Properties Class to parse this.

But inside the properties element, all the elements (emailId, createdDate, lastModifiedDate) are dynamic and another JSON may have 4 objects inside properties element e.g "phoneNumber".

Need help here to write the Properties class such a way that how much properties come inside the Properties element, those are some how converted into object inside the properties object.

Any help or hint will be appreciated. Thanks in Advance!

Rashed Hasan
  • 3,721
  • 11
  • 40
  • 82
  • probably duplicate.. Please follow this link for your answer. https://stackoverflow.com/questions/5796948/how-to-parse-dynamic-json-fields-with-gson – ap.singh Oct 11 '19 at 09:44

1 Answers1

0

You can do it this way. You can use Map, since your keys and values both are dynamic.

public class Wrapper {
   public Map<String, Map<String, String>> properties;
}

You can even get rid of the wrapper class and use Map<String, Map<String, String>> directly

pvpkiran
  • 25,582
  • 8
  • 87
  • 134