Search code examples
javaspringweb-servicesspring-restcontrollerspring-rest

Similar fields in DTO


I want to create a DTO. The DTO will be used to map HTTP request to a REST webservice in spring. My controller looks like this:

RequestMapping( value = DmsRestSvcApi.DOCUMENT_SEARCH_PATH, method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE } )
public List<DocSearchResponse> getDocumentInfoJson( @Validated @RequestBody DocSearchRequest oDocSearchRequest ) throws Exception {
    // do something
}

In the above signature the DocSearchRequest is the DTO I want to create. The DTO has some fields like:

private String searchCriteria1;
private String searchCriteria2;
/*
  .
  .
  .
 */
private String searchCriteria20;

// setters and getters.

Do we have a better way to implement the DTO? One thing to keep in mind is Spring uses reflection to set the values from the request to the DTO.


Solution

  • A List of cafeterias solved the problem. I have to send the request as a comma separated value ans Spring takes care of mapping. Same can be done for the Response.