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

Make serial descriptor equality (and hashcode) include the declared (use side) element names, rather than only the serial names of the element types. #2862

Closed
wants to merge 1 commit into from

Conversation

pdvrieze
Copy link
Contributor

@pdvrieze pdvrieze commented Nov 19, 2024

The xml parser uses the serial descriptor as part of the lookup key for extended type information. However, this does not work correctly if two serial descriptors have the same name and member types, even if the element names are different. This pull request includes the declared element names as part of the hash key and equals checking (I know that multiple types with the same @SerialName is not supposed to work, but with this change it at least breaks less.

The underlying bug is pdvrieze/xmlutil#254.

…use side) element names, rather than only the serial names of the element types. This fixes pdvrieze/xmlutil#254.
@pdvrieze pdvrieze changed the title Make serial descriptor equality (and hashcode) include the declared (use side) element names, rather than only the serial names of the element types. This fixes pdvrieze/xmlutil#254. Make serial descriptor equality (and hashcode) include the declared (use side) element names, rather than only the serial names of the element types. Nov 19, 2024
pdvrieze added a commit to pdvrieze/xmlutil that referenced this pull request Nov 19, 2024
underlying library (a pull request has been submitted: Kotlin/kotlinx.serialization#2862) for a fix. In the meantime either disabling the
cache or using `@XmlSerialName` instead of `@SerialName` will fix it.
@sandwwraith
Copy link
Member

I do not think we can change equals contract at this point, since it is part of a stable API and widely used now. Besides, the whole idea of comparing descriptors by something else except serialName is tied to generic classes — so Foo<String> can be distinguished from Foo<Int>, since their serialized form would be different. If the classes in question are not two generic flavors of one class but two different classes, they have to have different serial names.

For your issue, I can recommend either prohibit duplicated serial names, or make a serial descriptor wrapper to store in your cache — the wrapper would compare both serial descriptors and element names.

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

Successfully merging this pull request may close these issues.

2 participants