Announcement Announcement Module
Collapse
No announcement yet.
Convert JSON property to nested Object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Convert JSON property to nested Object

    Hi all,

    I want to update entity object with Jackson (Hibernate as ORM)

    Now, I have a problem converting this JSON to entity object:

    Code:
    {id: 1, name: "child name", parent: 1}
    Those JSON represents the following classes:
    Code:
    class Child {
        private int id;
        private String name;
    
        @ManyToOne // uni-directional many-to-one association to Parent
        @JoinColumn(name = "parent_id")
        private Parent parent;
    
        //getter and setter methods
    }
    Code:
    class Parent {
        private int id;
        private String name;
    
        //getter and setter methods
    }
    How to convert the "parent" property of those JSON to object of type Parent by supplying only ID = 1.
    What is the minimum configuration needed to solve this??

    Here is my mapping handler:
    Code:
    @RequestMapping(value = "/child/update", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, ?> update(@RequestBody Child child) {
    
          childDao.saveOrUpdate(child);
    
    }
    Thank you very much.
Working...
X