Mapper ignores @JacksonXmlProperty localname in Kotlin
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>
@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.
@cowtowncoder No, with Java it works as expected, the problem appears only in kotlin.
@fire-papaya
Is the same true if it is assigned to a get or field?
The situation appears to be similar to #658.