杰克逊:使用列表反序列化来映射XML

时间:2021-05-28 18:01:41

Is there a way to deserialize the following xml into Map holding List of items using Jackson?

有没有办法使用Jackson将以下xml反序列化为Map holding项目列表?

<order>
    <number>12345678</number>
    <amount>100.10</amount>
    <items>
        <item>
            <itemId>123</itemId>
            <amount>100.0</amount>
            <itemName>Item Name1</itemName>
        </item>
        <item>
            <itemId>234</itemId>
            <amount>200.00</amount>
            <itemName>Item Name1</itemName>
        </item>
    </items>
</order>

I tried with

我试过了

XmlMapper mapper = new XmlMapper();
LinkedHashMap map = (LinkedHashMap)mapper.readValue(xml, Object.class);

and got the following Map. The first item in the list is missing.

并获得以下地图。列表中的第一项缺失。

{
    order={
        number=12345678,
        amount=100.1,
        items={
            item={
                amount=200.0,
                itemName=ItemName2,
                itemId=234
            }
        }
    }
}

1 个解决方案

#1


0  

Created a custom deserializer by extending UntypedObjectDeserializer to do this job.

通过扩展UntypedObjectDeserializer来创建一个自定义反序列化器来完成这项工作。

#1


0  

Created a custom deserializer by extending UntypedObjectDeserializer to do this job.

通过扩展UntypedObjectDeserializer来创建一个自定义反序列化器来完成这项工作。