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

Issue with . in tag names #50

Closed
fkrauthan opened this issue Jan 20, 2021 · 5 comments
Closed

Issue with . in tag names #50

fkrauthan opened this issue Jan 20, 2021 · 5 comments
Labels
cantfix This issue cannot be resolved at this point because of limitations in external libraries. indev The issue is fixed/implemented in the dev branch

Comments

@fkrauthan
Copy link

I recently run into an issue where the XML I am consuming has tags like this: DISPLAYCONTACT.FIRSTNAME

My entity defines them like this:

    @XmlElement(true)
    @SerialName("DISPLAYCONTACT.FIRSTNAME")
    val firstName: String? = null,

in the same entity class all XML elements that do not have a . work fine and getting deserialized accordingly but all the once with . just getting ignored/skipped.

@fkrauthan
Copy link
Author

fkrauthan commented Jan 20, 2021

The strange thing is the unknownChildHandler is called for example for DISPLAYCONTACT.FIRSTNAME even though it's clearly deserialized.

I've debuged even further and looked at the unknownChildHandler candidates list and noticed that ALL of my attributes with a . in serial name show up BUT only the last part. So DISPLAYCONTACT.FIRSTNAME is listed as FIRSTNAME in the candidates. Thats why It can not find a match.

@fkrauthan
Copy link
Author

Ok for anyone that is running into the same issue a wrokaround is to use

@XmlSerialName("DISPLAYCONTACT.FIRSTNAME", "", "")

instead of

@SerialName("DISPLAYCONTACT.FIRSTNAME")

@pdvrieze
Copy link
Owner

pdvrieze commented Feb 1, 2021

I know what is going on. This is related to the mechanism that turns serialName values into tag names. For a type (rather than element) the serialName is the type name (if none is given with the annotation). Normally you don't want tag names with java packages in them (XML has namespaces for that).

This mechanism is implemented purely in the policy that you configure the format with. The default basically sees a . and assumes that this is a Kotlin type name and picks the final part only.

You can override this in serialNameToQName of the policy (you can extend DefaultXmlSerializationPolicy if you want). If you want (much) more control you can override effectiveName which is the user of that easier function (it is reasonably complex to deal with all kinds of special cases like built-in types as well as different policies for tags vs attributes).

The default implementation of serialNameToQName unfortunately provides no distinction between being called for the name of a type or for the name of an attribute. As names are part of the public API of serialization and a change in naming policy changes the names I can't really change the default without breaking peoples serialization. You could of course recognize specific names and special case them (positive or negative).

Unfortunately it is invisible to formats whether the @SerialName annotation was used. Which is the main reason that the @XmlSerialName annotation exists (btw. it is possible to process your own alternative annotations in effectiveName)

@pdvrieze pdvrieze added cantfix This issue cannot be resolved at this point because of limitations in external libraries. indev The issue is fixed/implemented in the dev branch labels Feb 1, 2021
@pdvrieze
Copy link
Owner

pdvrieze commented Feb 1, 2021

As this is basically an edge case in a (best effort) heuristic to resolve a design limitation of the serialization framework I'm not sure what I can do, except suggesting to use the available mechanisms to either provide your own naming policy, or provide annotations where appropriate.

What I have done is to split serialNameToQName into two functions: serialTypeNameToQName and serialUseNameToQName which by default delegate to it. The default code calls these, so the policy can now differ based upon context without too much code being needed.

@pdvrieze pdvrieze closed this as completed Feb 1, 2021
pdvrieze added a commit that referenced this issue Feb 1, 2021
issue #50 in that it makes it a bit easier to override the naming
heuristics.
@fkrauthan
Copy link
Author

Maybe this can be added to the documentation?

pdvrieze added a commit that referenced this issue Mar 25, 2021
issue #50 in that it makes it a bit easier to override the naming
heuristics.
pdvrieze added a commit that referenced this issue Apr 28, 2021
issue #50 in that it makes it a bit easier to override the naming
heuristics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cantfix This issue cannot be resolved at this point because of limitations in external libraries. indev The issue is fixed/implemented in the dev branch
Projects
None yet
Development

No branches or pull requests

2 participants