1

I have a in-house api (that I can't edit) that parses json into a POJO. The function looks like parse(String jsonString, Class jsonObj)

My problem is the the json string is dynamic. I don't always expect the same json object, so I want to avoid some ugly way of figuring out which json it is and pass in the correct class. It would be nice to skip creating a bunch of classes to pass in.

How do I achieve this? I was thinking maybe reflection but not sure yet.

12rad
  • 829
  • 2
  • 13
  • 28
  • see the google-gson https://code.google.com/p/google-gson/ – Asif Bhutto Apr 27 '14 at 11:18
  • see [Jackson library](http://www.mkyong.com/java/how-to-convert-java-object-to-from-json-jackson/) or [JavaEE JSON Processing](http://docs.oracle.com/javaee/7/tutorial/doc/jsonp.htm) – herau Apr 27 '14 at 11:41
  • possible duplicate of [Can I dynamically create a Java object in the run time via JSON?](http://stackoverflow.com/questions/11792286/can-i-dynamically-create-a-java-object-in-the-run-time-via-json) – herau Apr 27 '14 at 11:47
  • @herau I can do the json processing where the object is returned. What I want to achieve is creating that object at runtime or someway of dealing with the problem where I don't know what the object should look like. In the post you mentioned, it's the 2nd problem which hasn't been answered yet:( – 12rad Apr 27 '14 at 18:06
  • can you post your json – Asif Bhutto Apr 27 '14 at 18:09

0 Answers0