0

I have called a rest api from exsternal system using restTemplate. everything is work fine but when I get null in some of values (in example the footer value is null) it is always give jsonexception error

result api

{
    "status": "success",
    "data": {
        "id": "22",
        "organization_id": "33",
        "name": "name_isf",
        "language": "id",
        "header": {
            "format": "IMAGE",
            "example": "#<Hashie::Mash header_handle=#<Hashie::Array [\"result_pic"]>>"
        },
        "body": "contenty for body",
        "footer": null,
        "buttons": [],
        "status": "APPROVED",
        "category": "PERSONAL_FINANCE_UPDATE"
    }
}

every call api exsternal i always catch with jsonobject like below

JSONObject res2 = qontakService.getDetailTemplate();

then i will give that to the controller

JSONObject gabunganResult = new JSONObject();
gabunganResult.put("template", objectMapper.writeValueAsString(getDetail.get()));
gabunganResult.put("templateQontak", res2);

and the result error is

com.fasterxml.jackson.databind.JsonMappingException: Object is null (through reference chain: java.util.HashMap["details"]->net.sf.json.JSONObject["templateQontak"]->net.sf.json.JSONObject["data"]->net.sf.json.JSONObject["footer"]->net.sf.json.JSONNull["empty"])

how do I solve this problem ? thank you

3
  • stackoverflow.com/questions/51421295/… Commented Dec 24, 2022 at 8:34
  • it is in a class, whereas what I need is in the form of a jsonobject. I have tried it and still cant work Commented Dec 24, 2022 at 8:37
  • Can you give sample code to reproduce this issue? Commented Dec 24, 2022 at 9:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.