4 ms·
How do you even parse JSON in Java? I remember in the days of XML, there was a kind of specification standard for the xml (a specification for how to specify a
by facepalm 12y ago
How do you even parse JSON in Java? I remember in the days of XML, there was a kind of specification standard for the xml (a specification for how to specify a specification?). From that you could generate Java classes that would correspond to the elements of the XML. But for JSON there is no such meta description, so you are stuck with manually parsing the JSON and hoping you catch all nuances?
- jim_greco 12y agoThere's plenty of libraries for this. Jackson being the best one I've used.
- cgh 12y agoHave a look at the Jackson library. There are many others.
- larsmak 12y agoTypically you create your class manually and map to-and-from json-strings. In a web-context you'd usually let the container handle the serialization/de-serialization (jax-rs), in other contexts I tend to use Google's GSON-library.
- justinsb 12y agoI'd recommend Google Gson; it works either with model classes, or with a generic JsonObject. Jackson is good, and more powerful in terms of model mapping, but I find it much more complicated to work with.
- diltonm 12y agoGoogle's GSON is the one I've turned to on several projects.