lundi 30 mars 2015

how to change Spring 4 request param's model mapping config?

I am using Spring 4. I have this method:



@RequestMapping(value = {"clients/", "clients"}, method = RequestMethod.GET)
public ResponseEntity<PaginatedResponseDTO<ClientResponseDTO>> getClients(PaginationRequest params)
throws ValidationException {
// Logic
}


So, i am recieving request params in "PaginationRequest" model, which is



public class PaginationRequest {

private Integer offset;
private Integer limit;
@JsonProperty("order_by_criteria")
private List<String> orderByCriteria;
@JsonProperty("order_by_direction")
private List<String> orderByDirection;

// Getters and setters

}


The problem is that when i send "orderByCriteria" as request param, it works (by works i mean that i am recieving the value). But what i want to do is to pass that value with order_by_criteria param. I mean , i have already setted this to the mapper:



PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES


And this works when i serealize the object, but apparently Spring is not a json what Spring uses to model the object PaginationRequest. Somewhere i've red that that comes as a Map, that would explain why is not working with the objectMapper namingStrategy and the JsonProperty constraint that i've put on the fields.


Do you know how i could do that? Ultimately, it would be by calling this url:



http://localhost:8080/clients?order_by_criteria=asd,asd2


Then get an PaginationRequest with a List values at "orderByCriteria" field


Thanks in advance!


Aucun commentaire:

Enregistrer un commentaire