0

I have Big JSON payload and I am trying parse this Json into Target class. in the target class there is one filed which is String type. But JSON payload will have Object structure. When I parse this payload, Object Mapper throws an exception as can not deserialize from Object to String. Below is the class.

Class Properties{
String url;
String requestType;
String payload;
}

Sample Payload:     
"properties": {
        "url": "https://stackoverflow.com/questions",
        "requestType": "GET",
        "payload": {
            "testId": 123,
            "testName": "API",
            "description": "Call GET Request",
            "testCode": "STACKD001"
        }
    }

When I parse this payload it throws Cannot deserialize value of type java.lang.String from Object value for the property payload.

How to achieve without changing the JSON payload? I want the payload as String.

My JSON payload is much more complex than the sample one I provided here.

Note: I don't have control to add any ignore property to the Class property as it is generated from dependent module.

2
  • Please share your code. Commented Jan 12, 2024 at 4:37
  • ObjectMapper objectMapper = new ObjectMapper(); Properties properties = objectMapper.readValue(test.getProperties(), Properties.class); Commented Jan 12, 2024 at 16:44

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.