Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapper ignores @JacksonXmlProperty localname in Kotlin #517

Open
fire-papaya opened this issue Nov 8, 2021 · 3 comments
Open

Mapper ignores @JacksonXmlProperty localname in Kotlin #517

fire-papaya opened this issue Nov 8, 2021 · 3 comments

Comments

@fire-papaya
Copy link

When serializing Kotlin open class @JacksonXmlProperty localname is ignored

Dependencies and versions:

    implementation 'com.fasterxml.jackson.core:jackson-core:2.13.0'
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.0'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
    implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.0'
    implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.13.0'

I have a response model bean:

@JacksonXmlRootElement(localName = "Data")
open class DefaultResponse(
    open var errorCode: Int = 0,
    open var errorDescription: String = "OK",
    @Deprecated
    @JacksonXmlProperty(localName="ErrorId")
    open var ErrorId: Int = 0
)

which is returned by spring rest controller. When deserialized I receive:

<?xml version='1.0' encoding='UTF-8'?>
<Data>
    <errorCode>1</errorCode>
    <errorDescription>Error occurred</errorDescription>
    <errorId>1</errorId>
</Data>

But if I return Java object e.g.

@JacksonXmlRootElement(localName = "Data")
public class DefaultResponse {
    public DefaultWalletError(int errorCode, String errorDescription, int errorId) {
        this.errorCode = errorCode;
        this.errorDescription = errorDescription;
        ErrorId = errorId;
    }

    public Integer errorCode = 0;
    public String errorDescription = "OK";
    @JacksonXmlProperty(localName="ErrorId")
    public Integer ErrorId = 0;
}

The following body is received

<?xml version='1.0' encoding='UTF-8'?>
<Data>
    <errorCode>1</errorCode>
    <errorDescription>Error occurred</errorDescription>
    <ErrorId>1</ErrorId>
</Data>
@cowtowncoder
Copy link
Member

@fire-papaya Can this be reproduced with plain Java? If not, I'll move this to Kotlin module; XML module has no knowledge of Kotlin handling. If reproducible with just Java, can remain here but will need java-only reproduction.

@fire-papaya
Copy link
Author

@cowtowncoder No, with Java it works as expected, the problem appears only in kotlin.

@cowtowncoder cowtowncoder transferred this issue from FasterXML/jackson-dataformat-xml Nov 12, 2021
@k163377
Copy link
Contributor

k163377 commented Apr 2, 2023

@fire-papaya
Is the same true if it is assigned to a get or field?
The situation appears to be similar to #658.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants