2

I am having a JSON in which I have all the data as key-value pair. But my POJO is with nested class. How can I map the single level JSON into the nested class objects?

My JSON looks like this:

{
   "prototype" : {
            "name": "Deepak"
            "departmentId": "10"
            "departmentName": "IT"
            "address": "Bangalore"
            "state": "Karnataka"
   }
}

And my POJO looks like this:

class Prototype{
    String name;
    Department dept;
    Address address;
}

class Department {
    Integer departmentId;
    String departmentName;
}

class Address {
    String address;
    String state;
}

I tried using ObjectMaper but it only maps the name, other fields are not getting mapped. Does anyone knows how to achieve this

Deepak Kumar
  • 1,246
  • 14
  • 38
  • Does this answer your question? [Mapping a flat map to a nested pojo in jackson](https://stackoverflow.com/questions/48579978/mapping-a-flat-map-to-a-nested-pojo-in-jackson) – bkis Aug 11 '20 at 10:10
  • I have read this post already. I am looking for something if I can tell to Object mapper using som annotation or other configuration – Deepak Kumar Aug 11 '20 at 10:16
  • 2
    if you use Jackson, you can define custom deserializer [link](https://www.baeldung.com/jackson-deserialization). – Oleg Spiridonov Aug 11 '20 at 10:21

0 Answers0