stanlick
stanlick

Reputation: 1462

RestTemplate.postForObject and server side @RequestBody

Is is mandatory for the object sent through RestTemplate.postForObject to match exactly the type of object on the server side? I have written server a server side API that accepts a base class of the specific objects being sent through RestTemplate, and I'm receiving a 400 Bad Response from server. If the class of object is the same on both sides, it works fine.

Upvotes: 0

Views: 566

Answers (1)

akshay
akshay

Reputation: 106

Yes it is mandatory to match because resttemplate converts your object to specified representation(eg: into XMl or JSON) and at the serverside @requestbody unmarshalls to specifed object so if you are using baseclass, your root element changes making it impossible to unmarshal.

Hope this helps.

Upvotes: 1

Related Questions