What is the easiest way to convert / display a JSON string in javabean?

I have a JSON string that I read and would like to parse / map it to a JavaBean so that I can use it in my Java code. What is the easiest way / library for?

+4
source share
3 answers

XStream is renowned for ease of use and supports JSON:

http://x-stream.imtqy.com/json-tutorial.html

+2
source

I wrote a JSON library to do just that.

http://code.google.com/p/svenson/

With svenson you would do something like:

// assume json to be a JSON dataset as String MyBean bean = JSONParser.defaultJSONParser().parse(MyBean.class, json); 

Svenson gives you the freedom to use either maps / lists or your own POJOs to convert data to and from JSON.

+2
source

How about jackson ? As mentioned above, the mapping is pretty simple:

MyBean bean = new ObjectMapper (). readValue (json, MyBean.class);

handles maps, lists, primitives, beans; with proper generic support and a complete configuration of the mapping process.

+2
source

All Articles