1

I've used RestTemplate to consume remote REST API and I'm getting two different responses for the same request depend on data availability.

eg:- Valid Response

User { username, password }

Error Response when user not found in records.

Error { errorCode, errorMessage }

And this User response has mapped using restTemplate.getForEntity("url", User.class).

Additionally handled RestTemplate Errors using ResponseErrorHandler,

Is there any way to capture both User response and Error Response using resttemplate in same time?

1 Answer 1

1

I usually include both/all option and ignore null values, below example

@JsonInclude(Include.NON_NULL)
public class ResponseVO {
    private User user;

    private Error error;
}

If all data in same level, you can add all members in same class

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.