假设我的有效载荷类是:
public class Payload {
private final long id;
private final String aField;
}
springfox将按字典顺序对有效负载字段进行排序,这将生成以下有效负载规范:
{
"aField": "string",
"id": 0
}
是否有任何控制参数告诉springfox保留原始字段顺序?
答案 0 :(得分:5)
您可以使用@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;
}
答案 1 :(得分:0)
您可以在类的顶部使用一次@JsonPropertyOrder,然后将按照在类中定义的顺序对字段进行排序 https://www.logicbig.com/tutorials/misc/jackson/json-property-order-annotation.html