0
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dataset id="infoList">
        <rows>
            <row>
                <lvl>4</lvl>
                <itemCd>9999</itemCsfCd>
                <itemName>HELLO</itemCsfNm>
                <itemPrice>50</itemPrice>
            </row>
        </rows>
    </Dataset>
    <Dataset id="result">
        <rows>
            <row>
                <code>0000</code>
                <message>Success</message>
            </row>
        </rows>
    </Dataset>

There are two in different formats within the parent . Each Dataset is distinguished by its id property. I want to map this to an object using fasterxml.

I want to map it to

data class Response(
    val info: InfoDataset;

    val result: ResultDataset
)

not

data class Response(
    val datasetList: List<Dataset>
)

I tried

data class Response2XML(
    @JacksonXmlProperty(localName = "Dataset")
    val info: InfoDataset,

    @JacksonXmlProperty(localName = "Dataset")
    val result: ResultDataset
)

But Conflicting getter definitions for property "Dataset" error occured.

How do i solve this problem?

6
  • Jackson (fasterxml) is a Java library. Since you are using Kotlin, it might be nicer to use a library built for it, such as kotlinx.serialization. Having said that, it's certainly possible to do this with Jackson. Commented Oct 19, 2023 at 7:14
  • @Jorn The problem is that there are multiple <Dataset> in XML. The name is <Dataset>, but since the internal fields are different, I want to distinguish them by the id property of <Dataset id="dsList">, but if I use @JacksonXmlProperty(localName = "Dataset"), a conflict error occurs because they are two identical datasets. no see. Commented Oct 19, 2023 at 7:38
  • Yes, XML that's structured like that can be difficult to parse correctly. I don't have much experience with the XML side of Jackson, so I can't help you there. Commented Oct 19, 2023 at 7:40
  • that's right. It's a crappy data format. It's driving me crazy. Commented Oct 19, 2023 at 7:41
  • Perhaps you can parse it to a DTO structure that's as close to the XML as possible, then map it to a different set of of objects later. Commented Oct 19, 2023 at 7:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.