Search code examples
jsonparsingjacksonnestedpojo

How to Parse " Nested JSON " and set to POJO class


Jackson , How to Parse " Nested JSON " and set to POJO class

Sales.json

{
    "data": {
       "modified_by": "mat",
       "name": "mak",
        "net_total": 0,
        "items": [
            {
                "owner": "shoaib shaikh",
                "modified_by": "mat",
                "doctype": "Item"
             }
        ],
        "owner": "shoaib shaikh",
        "apply_discount_on": "tesla" 
        }
}

Solution

  • Describe your class Sales then do import com.fasterxml.jackson.databind.ObjectMapper; ... ObjectMapper mapper = new ObjectMapper(); Sales staff = mapper.readValue(new File("D:\\staff.json"), Sales.class);

    Some link to help: https://www.mkyong.com/java/jackson-2-convert-java-object-to-from-json/