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

你。 提交于 2020-01-23 07:38:13

问题


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?


回答1:


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;

}


来源:https://stackoverflow.com/questions/48949624/swaggerspring-is-it-possible-to-preserve-the-fields-order-in-the-payload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!