Skip to content

Serialization of same variable twice once with field name and other with localName provided in @JacksonXmlProperty #845

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

Closed
Mohit-Kumar23 opened this issue Nov 8, 2024 · 3 comments

Comments

@Mohit-Kumar23
Copy link

I have created a class of following structure in Kotlin:
class Specification
{
..... // Other fields

   @JacksonXmlProperty(localName = "RN")
     var rALNoField : Int? = null
	set(value) {
		field = value
	}

   ..... //Other fields

}

Now, when the "Specification" class is serialized, the xml contains two instances of rALNoField:

  1. With tag RN (that is correct)
  2. With tag ralnoField (which is duplicate of same variable)

This happens due to naming of variable, when I rename the variable to "ralnoField" it works fine and only RN is output. But when variable name is "rALNoField" it output 2 instance of same variable as mentioned above.

@cowtowncoder
Copy link
Member

Ok, pretty sure this is not XML-specific and has to do with name-mangling.
But more importantly, is Kotlin-specific; will move to Kotlin mode issue tracker .

@cowtowncoder cowtowncoder transferred this issue from FasterXML/jackson-dataformat-xml Nov 9, 2024
@cowtowncoder
Copy link
Member

note: My hypothesis being that use of @JsonProperty, output as JSON would exhibit same duplication. Which I think is due to either name used, or due to way annotations are associated for Kotlin classes.

Either way, issue cannot remain at XML module since wrt reproduction (cannot have dependency to Kotlin module).

@k163377
Copy link
Contributor

k163377 commented Nov 16, 2024

It is closed as a duplicate of #630
A possible solution is to enable KotrinPropertyNameAsImplicitName.

@k163377 k163377 closed this as completed Nov 16, 2024
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