0

I am reading the following json through a web service. Is there a way to read the json into three appropriate POJOs? The POJOs are generated by hibernate and are used to communicate to the database.

Basically I need to read the person json into a Person POJO, the pets json into a set of Pet POJOs, and the toy json into a set of Toy POJOs.

The JSON

{
"person":{"first_name":"John", "last_name":"Smith"},
"pets":[{"species":"dog", "name":"Adama"}, {"species":"cat", "name":"Benton"} ],
"toys":[{"car":"corvet", "color":"black"}, {"action_figure":"hancock", "height":"1ft"} ]
}

The Web Service

@Post
public Representation readForm(Representation representation) {
    try {
        Person aPerson = …
        Set<Pet>  petSet = …
        Set<Toy> toySet = ...

      ….
kasavbere
  • 5,873
  • 14
  • 49
  • 72

1 Answers1

0

You can use xStream . You will have to create a VO having all 3 types of your objects as properties. Give them respective aliases and you will get all 3 types of objects in that VO. You can get them simply by calling their getters.

Sumit Desai
  • 1,542
  • 9
  • 22