java - Return the List<myObj> returned by ResponseEntity<List> -
my rest client uses resttemplate obtain list of objects.
responseentitiy<list> res = resttemplate.postforentity(geturl(), mydto, list.class);
now want use list returned , return list calling class. in case of string, tostring used, work around lists?
first off, if know type of elements in list, may want use parameterizedtypereference
class so.
responseentity<list<myobj>> res = resttemplate.postforentity(geturl(), mydto, new parameterizedtypereference<list<myobj>>() {});
then if want return list can do:
return res.getbody();
and if care list, can do:
// postforentity returns responseentity, postforobject returns body directly. return resttemplate.postforobject(geturl(), mydto, new parameterizedtypereference<list<myobj>>() {});
Comments
Post a Comment