关于Jackson注解无效
@Entity
@Table(name="send_json_message")
@JsonPropertyOrder({"touser","msgType"})
public class JSONMessage implements Serializable {
/**
*
*/
private static final long serialVersionUID = 6191639680513644936L;
@JsonIgnore
private Integer id;
private String touser;
@JsonProperty(value="msgtype")
private String msgType;
@JsonIgnore
private Long createTime;
private Message message;
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getMsgType() {
return msgType;
}
public void setMsgType(String msgType) {
this.msgType = msgType;
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Embedded
public Message getMessage() {
return message;
}
public void setMessage(Message message) {
this.message = message;
}
/**
*
*/
public JSONMessage() {
super();
}
/**
* @param touser
* @param msgType
* @param createTime
* @param message
*/
public JSONMessage(String touser, String msgType, Long createTime,
Message message) {
super();
this.touser = touser;
this.msgType = msgType;
this.createTime = createTime;
this.message = message;
}
@Table(name="send_json_message")
@JsonPropertyOrder({"touser","msgType"})
public class JSONMessage implements Serializable {
/**
*
*/
private static final long serialVersionUID = 6191639680513644936L;
@JsonIgnore
private Integer id;
private String touser;
@JsonProperty(value="msgtype")
private String msgType;
@JsonIgnore
private Long createTime;
private Message message;
public String getTouser() {
return touser;
}
public void setTouser(String touser) {
this.touser = touser;
}
public String getMsgType() {
return msgType;
}
public void setMsgType(String msgType) {
this.msgType = msgType;
}
public Long getCreateTime() {
return createTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
}
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Embedded
public Message getMessage() {
return message;
}
public void setMessage(Message message) {
this.message = message;
}
/**
*
*/
public JSONMessage() {
super();
}
/**
* @param touser
* @param msgType
* @param createTime
* @param message
*/
public JSONMessage(String touser, String msgType, Long createTime,
Message message) {
super();
this.touser = touser;
this.msgType = msgType;
this.createTime = createTime;
this.message = message;
}
}
如上,我添加了@JsonPropertyOrder({"touser","msgType"}) ,可是输出的字符串的顺序还是不是我想要的,message、msgtype、touser,貌似一直是字典顺序,我关闭了字典排序也不管用,郁闷啊,这个解决呢?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MapperFeature#SORT_PROPERTIES_ALPHABETICALLY 默认是 false
objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);