So I had this problem of having to generated java classes from jsons. It seems like its all I ever do nowadays.
There is a great site that crawls a URL for you, reads the json, and reverse engineers some pojos for you : Its called JSONGen. However, its not OAuth validating - so you can't (for example) generate JSONs from a secure site using it.
So here is what you do .
0) Go to APigee, and get the JSON contents of your request using their console.
1) Go to pastebin, paste the contents of your json.
2) Paste the pastebin url as the input URL to JSONGen.
3) Tadaaaa download your source code and import it.
Yipeeee !
Now that you have the beans modelling your data --- what if your JSON wasn't a good representative ? Well then just add support for unknown fields (if using Jackson - you can do this as prescribed here http://stackoverflow.com/questions/8889296/jackson-avoiding-exceptions-due-to-unmodeled-fields).
No comments:
Post a Comment