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

标签 java spring swagger springfox

假设我的负载类是:

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

springfox 将按字典顺序对有效载荷字段进行排序,这将产生以下有效载荷规范:

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

是否有任何控制参数告诉 springfox 保留原始字段顺序?

最佳答案

您可以使用 @ApiModelProperty并指定一个 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;

}

关于java - Swagger + Spring : is it possible to preserve the fields order in the payload?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48949624/

相关文章:

java - 无法使用 Intent 启动新 Activity

java - 无法检索亚马逊凭据

java - SDN 4.2 嵌入式 Autowiring Neo4j OGM session

spring-boot - 我得到 404 的 https ://localhost:8080/swagger-ui. html

c# - Azure API App 客户端不生成枚举

REST API 设计指南合规性测试

java - 使用jdbc访问excel作为数据库

java - 如何在带注释的 UIThreadTest 方法中说 waitForIdleSync()

java - 如何在 Spring 上下文文件中使用带有属性文件的环境变量

java - 本地 H2 服务器 + hibernate : existing database is not visible