本文介绍了@JsonRootName无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的FacilityDTO
@JsonRootName("Facility")
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(name = "Facility", propOrder = { "id", "name", "totalQuantity" })
public class FacilityDTO implements Serializable {
private static final long serialVersionUID = 1L;
@XmlElement(required = true)
private String id;
@XmlElement(required = true)
private String name;
@XmlElement(required = true)
private double totalQuantity;
public FacilityDTO() {
}
public FacilityDTO(Facility facility) {
this.name = facility.getName();
this.totalQuantity = facility.getTotalQuantity();
this.id = facility.getId();
}// getters setter
这是我的邮件正文撰稿人
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk7Module());
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
mapper.writeValue(out, object);
int bytesCount = out.size();
byte[] bytes = out.toByteArray();
entityStream.write(bytes);
entityStream.flush();
JSON格式的输出是这样的
我的问题是:
- 为什么结果看起来不正确?我被置于@JsonRootName(Facility)并启用了换行根功能。
- 我想念的任何部分?
推荐答案
请参阅
根据以上所述,您需要按如下方式配置反序列化:
mapper.configure( DerializationFeature.UNWRAP_ROOT_VALUE,true);
According to the above, you need to configure deserialization as follows:mapper.configure(DerializationFeature.UNWRAP_ROOT_VALUE, true);
这篇关于@JsonRootName无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!