1 Reply Latest reply: Sep 29, 2012 11:25 AM by 965123 RSS

    Reading JSON thru web service into POJOs annotated for Hibernate

    964392
      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 = ...

      ….
      }


      Now of course I know I can use Jackson to convert JSON to POJO. But the problem is that the POJOs in question are annotated (EJB) for hibernate. So is it acceptable to mix and match annotations like that?