Ghassen
Ghassen

Reputation: 781

Generating POJO instances from Json

Is there a lib to create POJO instance from Json ?

Actually I'm using JJSchema to generate a full Json from the POJO but I can't find to do the reverse.

PS : My POJO is have other POJOs as attributes.

Upvotes: 1

Views: 3674

Answers (2)

Philip Koch
Philip Koch

Reputation: 347

You should give FasterXML Jackson a try. In my opinion it is very straight forward and easy to use. Here's the example from the github page that describes how a Java Object can be created from JSON

ObjectMapper mapper = new ObjectMapper(); // create once, reuse
MyValue value = mapper.readValue(new File("data.json"), MyValue.class);
// or:
value = mapper.readValue(new URL("http://some.com/api/entry.json"), MyValue.class);
// or:
value = mapper.readValue("{\"name\":\"Bob\", \"age\":13}", MyValue.class);

Upvotes: 2

Abhishek kumar
Abhishek kumar

Reputation: 4445

You can use this site to Generate Plain Old Java Objects POJO from JSON or JSON-Schemay.

http://www.jsonschema2pojo.org/

Upvotes: 0

Related Questions