Tuesday, February 20, 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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...