Java @JsonRootName不能按我所希望的那样工作

Java @JsonRootName不能按我所希望的那样工作,java,json,jaxb,jackson,root,Java,Json,Jaxb,Jackson,Root,这是我的设备 @JsonRootName("Facility") @XmlAccessorType(XmlAccessType.NONE) @XmlType(name = "Facility", propOrder = { "id", "name", "totalQuantity" }) public class FacilityDTO implements Serializable { private static final long serialVersionUID = 1L; @Xm

这是我的设备

@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”)上,还启用了wrap root特性
  • 我错过了什么
  • 根据以上内容,您需要按如下方式配置反序列化:
    mapper.configure(deralizationfeature.UNWRAP\u ROOT\u值,true)

    我认为(尽管我可能错了),这是因为它是作为LinkedList的元素返回的。如果您只返回一个设备,它应该可以正常工作。