大家好,又见面了,我是你们的朋友全栈君。
使⽤ordinal指定字段的顺序
public class BasePackage {
@JSONField(ordinal = 1)
private int id;
@JSONField(ordinal = 2)
private int direction;
@JSONField(ordinal = 3)
private String type;
@JSONField(ordinal = 5)
private byte crc;
@JSONField(ordinal = 4)
private Object body;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getDirection() {
return direction;
}
public void setDirection(int direction) {
this.direction = direction;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public byte getCrc() {
return crc;
}
public void setCrc(byte crc) {
this.crc = crc;
}
public Object getBody() {
return body;
}
public void setBody(Object body) {
this.body = body;
}
}
赋值后转为json字符串后的结果举例:
{"id":2,"direction":0,"type":"input","body":{"no":21},"crc":204}#
字段的顺序即为ordinal标注的顺序
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/127018.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...