【发布时间】:2018-12-30 06:33:21
【问题描述】:
如果我有类似的模式可以生成:
<xsd:complexType name="address_listType">
<xsd:sequence>
<xsd:element name="input_location" type="input_locationType"
maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
然后我创建了一个带有 Jackson 注释的 bean,例如:
@JsonPropertyOrder({ "input_location" })
public class AddressListTypeImpl implements AddressListType {
private List<InputLocationType> m_inputLocationTypes = new ArrayList<>();
@Override
@JsonProperty("input_location")
public InputLocationType[] getInputLocationArray() {
return m_inputLocationTypes.toArray(new InputLocationType[m_inputLocationTypes.size()]);
}
}
当我将此 bean 转换为 xml 时,使用:
XmlMapper xmlMapper = new XmlMapper();
return xmlMapper.writeValueAsString(myAddressList);
我明白了:
<input_location>
<input_location x="X:4" multimatchNumber="1000" id="ID:1" latitude="80.2" longitude="44.1" srid="SRID: 5" y="Y:2">
</input_location>
</input_location>
但是考虑到我必须生成的架构,我不希望集合为自己输出一个节点,只为集合中的每个元素输出一个节点。
我如何告诉杰克逊不要为集合本身生成节点?
【问题讨论】:
标签: java xml serialization jackson