java - Post class object to RESTful web service -


i have 2 classes:

public class person {         private string name;     private integer age;     private string surname;      // getters , setters }  public class animal {      private string name;     private integer age;      // getters , setters } 

and thing wanna - post animal.class , receive response in person.class format. (on client side).

for purpose i'm using rest template:

resttemplate resttemplate = new resttemplate(); person result = resttemplate.postforobject("http://url.com", httpmethod.post, animal.class, person.class); 

i know passing animal.class way not right, cannot set name , age parameters manually in page. main requirement use post method.

so have make work?

i believe looking is:

resttemplate resttemplate = new resttemplate(); httpentity<animal> request = new httpentity<>(animal); //populated object responseentity<person> response = resttemplate.   exchange(url, httpmethod.post, request, person.class); 

Comments