Spring RestTemplate: How to serialize java.util.Collection

I need to call a RESTful webservice from a Java program and pass it to a DateTime Collection.

So, my code is like the 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());

    for (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,
} catch (URISyntaxException e) {
} catch (DataAccessException e) {

And the webservice’s signature is 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 I get the error:

org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: No serializer found for class java.util.Collections$3 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) )

I understand that the problem is the serialization of the collection, but I do not know how to solve it.

I also tried with a Command class, so something like:

public class CalcolaGiorniResiduiCommand implements Serializable {
    private List<DateTime> dates;

Changed the 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 is a DateTime Collection
restTemplate.postForObject(apiUri.toString(), request, BigDecimal.class, command);

But I get the same error.

Any help, please?

I think you have to pass a list of dateTime object rather than adding it multiple time. Can you please try with the below snippet.
 List<DateTime> dates = new ArrayList<>();

 for (DateTime date : dates) {
requestParams.add("dates", dates);