How to map Request parameters with SNAKE case to a Pojo, and generate the correct API docs with swagger?

Viewed 240

I'm working on a RESTful API using Spring Boot 2.2.11, and generating API docs by Springfox 3.0.1. For some reason, I have to map the fields of Java pojos to json with SNAKE case, so I added a line in application.properties below, and it works well while handling request body and response body.

spring.jackson.property-naming-strategy=SNAKE_CASE

But it doesn't work while I add a pojo with @RequestParam or @ModelAttribute, the fields in API docs generated by swagger are CAMEL case, and Spring mvc can't map the request parameters with SNAKE case to the pojo of course.

Here is the pojo:

@Data
public class PageParameter {
    private int pageSize;
    private int pageNumber;
}

The controller:

@Api(tags = "Pagination Demo")
@RestController
public class PageController {
    @GetMapping("/pairs")
    @ApiOperation("Query pairs with pagination")
    Page<Pair> queryPairs(@ModelAttribute PageParameter parameter) {
        return null;
    }
}

The API doc fragment:

{
  "/pairs": {
    "get": {
      "tags": [
        "PaginationDemo"
      ],
      "summary": "Querypairswithpagination",
      "operationId": "queryPairsUsingGET",
      "parameters": [
        {
          "name": "pageNumber",
          "in": "query",
          "description": "Theindexofpagination",
          "required": false,
          "style": "form",
          "schema": {
            "type": "integer",
            "format": "int32"
          }
        },
        {
          "name": "pageSize",
          "in": "query",
          "description": "Thesizeofrecordsperpage",
          "required": false,
          "style": "form",
          "schema": {
            "type": "integer",
            "format": "int32"
          }
        }
      ],
      "responses": {
        
      }
    }
  }
}
0 Answers
Related