【问题标题】:Eliminating production of collection node for maxOccurs="unbounded" collections with Jackson in java在 java 中使用 Jackson 消除 maxOccurs="unbounded" 集合的集合节点的生成
【发布时间】: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


    【解决方案1】:

    找到了:

    @JacksonXmlElementWrapper(useWrapping = false)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-05
      • 2016-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多