Spring RestTemplate: How to serialize java.util.Collection -


i need call restful webservice java program , pass datetime collection.

so, code following:

resttemplate resttemplate = new resttemplate(); try {     string scheme = request.getscheme();     string userinfo = request.getremoteuser();     string host = request.getlocaladdr();     int port = request.getlocalport();     string path = "/myapp/common/myapi";      multivaluemap<string, object> requestparams = new linkedmultivaluemap<string, object>();      requestparams.add("aid", obja.getid());     requestparams.add("bib", objb.getid());      (datetime date : dates) {         requestparams.add("dates", date);     }      uri apiuri = new uri(scheme, userinfo, host, port, path, null, null);     result = resttemplate.postforobject(apiuri.tostring(), request, bigdecimal.class,             requestparams); } catch (urisyntaxexception e) {     logger.error(e.getmessage()); } catch (dataaccessexception e) {     logger.error(e.getmessage()); } 

and webservice's signature like:

@requestmapping(value = "myapi", method = requestmethod.post) public @responsebody bigdecimal myapi(         @requestparam("dates") final list<datetime> dates,         @requestparam("aid") final integer aid, @requestparam("bid") final integer bid) {      [...]      return result;  } 

but error:

org.springframework.http.converter.httpmessagenotwritableexception: not write json: no serializer found class java.util.collections$3 , no properties discovered create beanserializer (to avoid exception, disable serializationconfig.feature.fail_on_empty_beans) )

i understand problem serialization of collection, not know how solve it.

updated tried command class, like:

public class calcolagiorniresiduicommand implements serializable {     private list<datetime> dates;     //[...] } 

changed controller:

@requestmapping(value = "myapi", method = requestmethod.post) public @responsebody bigdecimal myapi(         @requestparam("command") final mycommand command) { 

and finally:

mycommand command = mycommand.build(1, 1, dates); //dates datetime collection resttemplate.postforobject(apiuri.tostring(), request, bigdecimal.class, command); 

but same error.

any help, please?

i think have pass list of datetime object rather adding multiple time. can please try below snippet.  list<datetime> dates = new arraylist<>();   (datetime date : dates) {         dates.add(date);     } requestparams.add("dates", dates); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -