java - @JsonRootName not work as I want -
this 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
this message body writer
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();
the output of json format this
my questions are:
- why results seem not correct? put @jsonrootname("facility") , enable wrap root feature.
- any part miss?
see jackson json deserialization root element
according above, need configure deserialization follows: mapper.configure(derializationfeature.unwrap_root_value, true);
Comments
Post a Comment