java


Resttemplate: Get an List of Object by passing one Object to the RestAPI [duplicate]


I want to make a service with Spring's RestTemplate, in my service side the code is like this :
#PostMapping(path="/savePersonList")
#ResponseBody
public List<Person> generatePersonList(#RequestBody List<Person> person){
return iPersonRestService.generatePersonList(person);
}
In client side if I call the service with this code:
List<Person> p = (List<Person>) restTemplate.postForObject(url, PersonList, List.class);
I can't use the p object as List<Person>, it will become a LinkedHashList.
After some research I find a solution that said I have to call the service with exchange method:
ResponseEntity<List<Person>> rateResponse = restTemplate.exchange(url, HttpMethod.POST, personListResult, new ParameterizedTypeReference<List<Person>>() {});
and with this solution the server can't take the object and raise an exception , what's the correct way?
Check if your code is like below. This should work.
//header
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
//person list
List<Person> personList = new ArrayList<Person>();
Person person = new Person();
person.setName("UserOne");
personList.add(person);
//httpEnitity
HttpEntity<Object> requestEntity = new HttpEntity<Object>(personList,headers);
ResponseEntity<List<Person>> rateResponse = restTemplate.exchange(url, HttpMethod.POST, requestEntity,new ParameterizedTypeReference<List<Person>>() {});

Related Links

Android app black screen ( onCreate() )
Java: Converting a String into an Int recursively?
Reducing java security settings
How to check if the guard is working against CSRF attacks on my site? [duplicate]
Problems using image resources of plug in jars
Searching in Oxford Dictionary
Class in JAR file not Autowired
Expose Liferay functions to another web application
Are compiled Java 8 lambda expressions backwards compatible with earlier versions of the Java runtime?
How to ignore case in replace method java [duplicate]
java regex selecting until string but not substring
OSGI Classloading & Object Sharing
Accessing variable from another class
Extending spring security UsernamePasswordAuthenticationFilter
Any Javadoc style documentation tool for MyBatis XML sqlmaps?
how to design query layer in CQRS

Categories

HOME
bluetooth
blogger
hashmap
vmware
octobercms
yarn
frameworks
c#-2.0
umd
callback
baqend
mvvmcross
azure-media-services
primary-key
gorm
facebook-php-sdk
circular-dependency
windows-phone-7
percona
try-catch
clearcase-ucm
clojurescript
seaborn
pc
propel
jtextfield
csrf-protection
facebook-instant-articles
angular2-aot
h2db
publish
dbclient
bpel
yadcf
ioio
noraui
uiswipegesturerecognizer
accelerate-framework
google-api-nodejs-client
hexo
wpf-controls
overriding
http-digest
revolution-slider
swisscomdev
event-driven
user-controls
sql-server-agent
outlook-api
angular2-meteor
logfiles
pango
dds
paxos
blogengine.net
setter
kbuild
memory-alignment
imanage
webdriverjs
root-framework
word-vba-mac
angular-cache
log4c
asp.net-4.5
mathematica-frontend
plottable.js
flash-cs5
lua-5.1
prettytensor
suffix-tree
ipconfig
historian
sdhc
endeca-workbench
intellij-14
security-testing
dukescript
embedded-code
ideamart
python-green
offloading
dd
gui-test-framework
cctv
titanium-modules
markers
issuu
neolane
has-many-through
xceed-datagrid
cloud-connect
algebraic-data-types
industrial
inbox
excel-2003
lcs
flashvars
osql
postgresql-performance
removeclass
gnu-prolog
recent-documents
disclosure
lpeg
visitor-statistic
cxxtest
preference
castle-monorail
avatar
ajax-forms

Resources

Encrypt Message