0

I have a JSON that I get with ObjectNode.

However, I can not get the ID of the object "LibellePrerequis" Is the method used the right one?

if I do :

String libelleprerequis = objectNode.get("id").asText();

I have the id of the script

{
"script":{
"id":2,
"name_script":"tes",
"libellePrerequis": {"id":3, "name_libelle":"Soc contrat VAM"}
}

My controller :

    @PostMapping("/create")
        public ResponseEntity<Script> updateScriptLibellePrerequis(@RequestBody ObjectNode objectNode) {
            String libelleprerequis = objectNode.get("libellePrerequis.id").asText();
            System.out.println("Libelle Prerequis with ID = " + libelleprerequis + "...");
}

error :

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException: null

7
  • Your id is a numeric value. You try to get it asText. Is this correct? Commented May 6, 2019 at 14:04
  • i try to make asInt and asLong .. and i try libellePrerequis.name_libelle with asText and same error Commented May 6, 2019 at 14:04
  • what's the error? Commented May 6, 2019 at 14:10
  • Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException: null Commented May 6, 2019 at 14:10
  • 1
    try objectNode.get("libellePrerequis").get("id").asText() as this should return objectNode.get("libellePrerequis") JsonNode Object Commented May 6, 2019 at 14:38

1 Answer 1

2

try objectNode.get("libellePrerequis").get("id").asText() as this should return objectNode.get("libellePrerequis")is a JsonNode Object

Sign up to request clarification or add additional context in comments.

Comments

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.