I have this String an I covered it to jsonNode using the ObjectMapper. Then I tried to look for a pecific key in this jsonNode so I used the ".has" but it did not work !! Here is what I did :
{
"links": {
"data": {
"self": {
"body": "",
"content_type": "",
"href": "/api/v2/nodes",
"method": "POST",
"name": ""
}
}
},
"results": {
"data": {
"properties": {
"container": true,
"container_size": 0,
"create_date": "2020-06-22T16:19:07",
"create_user_id": 1000,
"description": ""
"description_multilingual": {
"en": "",
"fr_FR": ""
},
"external_create_date": null,
"external_identity": "",
"external_identity_type": "",
"external_modify_date": null,
"external_source": "",
"favorite": false,
"id": 276625,
"mime_type": null,
"modify_date": "2020-06-22T16:19:07",
"modify_user_id": 1000,
"name": "mar",
"name_multilingual": {
"en": "mar",
"fr_FR": ""
},
"owner": "Admin",
"owner_group_id": 1001,
"owner_user_id": 1000,
"parent_id": 2000,
"permissions_model": "advanced",
"reserved": false,
"reserved_date": null,
"reserved_shared_collaboration": false,
"reserved_user_id": 0,
"size": 0,
"size_formatted": "0 Eléments",
"type": 0,
"type_name": "Dossier",
"versions_control_advanced": false,
"volume_id": -2000
}
}
}
}
and I want to test whether it has the "id" key (it actually exists in line 31) so I used .has()
as mentioned in How to check if a json key exists?:
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode= mapper.readTree(body);
if(rootNode.has("id")){
System.out.println(true);
}
else{
System.out.println(false);
}
but always it shows me "false" as output !!