Jackson-无法从VALUE_STRING中反序列化java.util.ArrayList的实例

时间:2018-06-25 15:29:15

标签: kotlin jackson

我试图反序列化从Web服务到Kotlin类的XML响应,并得到主题行中提到的错误。我试过按照前面提到的建议添加标志ACCEPT_SINGLE_VALUE_AS_ARRAY的建议,但是它不起作用。我的Kotlin类具有嵌套的数据对象。这里缺少什么?我在所有List对象上都遇到了错误。

这是Web服务的响应。

<RootNode>
        <Node1>
            <Content>A1</Content>
            <Content>A2</Content>
            <Node2>
                <Item>
                    <D1>1</D1>
                    <D2>0</D2>
                </Item>
                <Item>
                    <D1>2</D1>
                    <D2>0</D2>
                </Item>
            </Node2>
            <Node3>
                <NodeDetail>
                    <S1>A23</S1>
                    <S2>BN</S2>
                    <S3>
                        <Code>
                            <P1>1</P1>
                            <P2>2</P2>>
                        </Code>
                        <Code>
                            <P1>3</P1>
                            <P2>4</P2>
                        </Code>
                    </S3>
                </NodeDetail>
            </Node3>
        </Node1>
    </RootNode>

为此定义的Kotlin数据类:

@JsonIgnoreProperties(ignoreUnknown = true)
data class RootNode (
        @JacksonXmlProperty(localName = "RootNode")
        var baseNode: BaseNode? = null
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class BaseNode (
        @JacksonXmlProperty(localName = "Node1")
        var node1: Node1? = null,
        @JacksonXmlProperty(localName = "Node2")
        var node2: Node2? = null
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class Node1 (
        @JacksonXmlProperty(localName = "Item")
        var item: List<Item>? = null
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class Item (
        @JacksonXmlProperty(localName = "D1")
        var d1: Int? = null,
        @JacksonXmlProperty(localName = "D2")
        var d2: Int? = null
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class Node2 (
        @JacksonXmlProperty(localName = "NodeDetail")
        var nodeDetail: NodeDetail? = null
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class NodeDetail (
        @JacksonXmlProperty(localName = "S1")
        var s1: S1? = null
        @JacksonXmlProperty(localName = "S2")
        var s2: S2? = null
        @JacksonXmlProperty(localName = "S3")
        var s3: S3? = null
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class S3 (
        @JacksonXmlProperty(localName = "Code")
        var code: Code? = null
)

@JsonIgnoreProperties(ignoreUnknown = true)
data class Code (
        @JacksonXmlProperty(localName = "P1")
        var p1: String? = null,
        @JacksonXmlProperty(localName = "P2")
        var p2: String? = null
)

0 个答案:

没有答案