Tuesday, 20 February 2018

java - Parse JSONNode using Jackson

I have a JSONNode called itemNode that looks like the following JSON. It is obtained in the function parse() below:





"items": [
{
"base": true,
"component": {
"order_id": 9,
"discriminator": "ALL",
"product_type": "shoelace",
"customer_id": 6,
"id": "yyy"

},
"component_id": "123",
"limit": 4
},
{
"base": false,
"component": {
"order_id": 9,
"discriminator": "ALL",
"product_type": "shoes",

"customer_id": 3,
"id": "xxx"
},
"component_id": "124",
"limit": 1
}
]




Below is how my function looks like:




@Override
public Optional> parse(JsonNode rootNode, String parsePath) {
JsonNode itemNode = parseAttributePath(rootNode, parsePath);
//TODO
// Get the base, product_type, limit from itemNode
}


public JsonNode parseAttributePath(JsonNode rootNode, String parsePath) {
return rootNode.at(parsePath);
}



I have a List where Items is a class containing:
base, product_type, limit



I need to parse the itemNode in the parse() function to get only the above 3 values.




Please give me some pointers to get only the attributes that I want. Thanks in advance.

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...