1

I receive from a web service a list of json objects that may containing different keys. Eg one would have a title, a url and a list of picture urls, another one would have the same more a phone number... I need to keep these objects in memory but I'm not sure about the best way to do it.

1- I could keep the JSONObject as it is.

2- I could create an array of generic Item object with all the possible fields (most are common to all items) and for each instance set only the fields which have the corresponding keys in the json object, and leave the others null.

3- I could also create for each object a map with the keys contained by the item.

Any thoughts about the best method?

Thanks

Jul

3
  • i'd go with option 2. use google GSON! Commented May 23, 2011 at 18:21
  • @binnyb What happens if a field of the java object is not present in the json? Is it set to null? Commented May 23, 2011 at 18:28
  • Yes, null. see the GSON documentation Commented May 23, 2011 at 18:31

1 Answer 1

2

I would look at Jackson or GSON for JSON object mapping.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.