POST JSON object using Spring REST template -


i posting json object using spring rest template. works fine less data, posting more data throws request uri long error.

       final string url = getserviceurl() + "/rs/doc?param1=test";          resttemplate resttemp=getresttemplate();          httpheaders headers = new httpheaders();         headers.setcontenttype(org.springframework.http.mediatype.application_json);          //set entity send         httpentity<mybean> request = new httpentity<mybean>(mybean,headers);          list<httpmessageconverter<?>> messageconverters = new arraylist<httpmessageconverter<?>>();         messageconverters.add(new mappingjacksonhttpmessageconverter());         messageconverters.add(new formhttpmessageconverter());         resttemp.getmessageconverters().addall(messageconverters);          // send it!         responseentity = resttemp.exchange(url, httpmethod.post, request, string.class); 

the request body should accept unlimited data in post method. doesn't seem work here. can please guide.

the way created posts testing purposes use postforentity method available through spring. set responseentity accept maps (responseentity<map>) , used map.class instead of string.class. allows use key value pairs when inputting json data (you can use hashmap). may require change httpentity type map set map accept mybean class have set. hope helps!


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -