关于Jackson注解无效

feihui 发布于 2014/11/06 11:03
阅读 3K+
收藏 0
@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;
}

}

如上,我添加了@JsonPropertyOrder({"touser","msgType"}) ,可是输出的字符串的顺序还是不是我想要的,message、msgtype、touser,貌似一直是字典顺序,我关闭了字典排序也不管用,郁闷啊,这个解决呢?

加载中
0
阿影
阿影

MapperFeature#SORT_PROPERTIES_ALPHABETICALLY 默认是 false

objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);


返回顶部
顶部