Skip to content
Advertisement

How to read the response of a REST api in spring boot [closed]

I am making request to a post API using RestTemplate which will give response as application/json { “BuzRules”:{ “Id”: “1234”, “Unit”: “ou12”, “CaId”: “abc43” }, “verifyRule”:{ “isValidId”: false, “isValidUnit”: true, “isValidCaId”: false } }

I need to read the all attributes of verifyRule and if the any of these are false then will set a message that “I’d is wrong, provide correct I’d to verify the rule correctly”.

Please provide some working examples. THANKS IN ADVANCE.

Advertisement

Answer

You can try to define correct DTO in your source code with all the attributes of the answer. And then you can try to accept response in this way ResponseEntity<DTO> response = 'request code'.

Or you can just parse given json by com.fasterxml.jackson.databind.ObjectMapper in correct DTO class. It will looks like this: DTO response = objectMapper.readValue(jsonString, DTO.class);

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement