spring-bootjson-api

Spring boot map subset of json to pojo


I have a json as defined below:

{
"data": [
   {
    "type": "hosts",    
    "attributes": {
        "element1": "value1",
        "element2": "value2"
  }
}
]
}

I would like spring to only look at "attributes" node and marshall it into a pojo that is defined by "type" resource. The json is in json-api spec and will be enhanced in the future to be fully compatible with the spec.

Any pointers on how to approach this issue?

Thanks, Navin


Solution

  • I think you can use ObjectMapper to parse JSON objects to a mapper. See here:

    Jackson JSON – Converting JSON to Map

    http://www.journaldev.com/2324/jackson-json-java-parser-api-example-tutorial