Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger+Spring: is it possible to preserve the fields order in the payload?

Assuming my payload class is:

public class Payload {
  private final long id;
  private final String aField;
}

springfox will sort the payload fields in the lexicographical order which will produce the following payload spec:

{
  "aField": "string",
  "id": 0
} 

Is there any control parameter which tells the springfox to preserve the original fields order?

like image 821
Sergey Pauk Avatar asked Feb 23 '18 14:02

Sergey Pauk


1 Answers

You may use @ApiModelProperty and specify a position :

public class Payload {

  @ApiModelProperty(value = "The id", position = 1)
  private final long id;
  @ApiModelProperty(value = "The a field", position = 2)
  private final String aField;

}
like image 105
Arnaud Avatar answered Sep 19 '22 21:09

Arnaud