Search code examples
javajacksondeserializationfasterxml

Java Deserialization


I have xml response like that

        <service>Service name</service>
        ...
        some fields
        ...
        <service>
            <min_amount>6</min_amount>
            <max_amount>1522</max_amount>
            <max_limit>3000</max_limit>
            <currency>USD</currency>
        </service>

and i need to deserialize it into POJO

@JacksonXmlProperty(localName = "service")
private String service;

... some more fields ...

@JacksonXmlProperty(localName = "service")
private Service serviceObject;

but i'm getting com.fasterxml.jackson.databind.JsonMappingException: Multiple fields representing property "service", how can i solve that?


Solution

  • The structure of your XML response is not valid, so it may be impossible to map it correctly for (de)serialization.

    You have two tags with the same name service , but with different structure.

    I assume you are not the owner of service, producing this XML, but one of this tag should be rename, or two separate namespaces should be used for them.