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

fix: correctly deserialize consecutive XML flat maps #879

Merged
merged 2 commits into from
Jun 30, 2023

Conversation

lauzadis
Copy link
Contributor

@lauzadis lauzadis commented Jun 28, 2023

This PR fixes a bug in the XML deserializer which fails to process consecutive flat maps properly. Before this change, the deserializer would seek forward until it found a matching map key. Consecutive flat maps sharing the same key names would be lumped together unintentionally.

The fix is to seek using XmlSerialName as a comparator since this is the only thing distinguishing different flat maps. A new deserialize method peekSeek is added which seeks forward and only consumes tokens if they are a match.

Issue #

awslabs/aws-sdk-kotlin#962

Description of changes

This fixes a bug when deserializing consecutive flat maps. See the new "consecutive flat maps" test case for an example of an XML tree for which parsing previously failed.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lauzadis lauzadis force-pushed the fix-xml-flatmap-deserializer branch from 04ab28e to 0cc29b1 Compare June 30, 2023 16:13
@lauzadis lauzadis marked this pull request as ready for review June 30, 2023 16:33
@lauzadis lauzadis requested a review from a team as a code owner June 30, 2023 16:33
Copy link
Contributor

@ianbotsf ianbotsf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems right to me. Do we have similar problems in our other deserializers (e.g., JSON)?

Comment on lines 107 to 114
val compareTo = when (descriptor.hasTrait<Flattened>()) {
// Prefer seeking to XmlSerialName if the trait exists
true -> when (descriptor.hasTrait<XmlSerialName>()) {
true -> descriptor.expectTrait<XmlSerialName>().name
false -> mapTrait.key
}
false -> mapTrait.entry
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: I generally find when/true/false to be less readable than if/else or null-coalescing. In this case, when (descriptor.hasTrait<XmlSerialName>()) { ... } can be replaced with:

descriptor.findTrait<XmlSerialName>()?.name ?: mapTrait.key

@lauzadis
Copy link
Contributor Author

Do we have similar problems in our other deserializers (e.g., JSON)?

Thankfully JSON doesn't have this problem because it only has one way to represent a map

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

No Coverage information No Coverage information
51.9% 51.9% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@lauzadis lauzadis merged commit 422e04e into main Jun 30, 2023
@lauzadis lauzadis deleted the fix-xml-flatmap-deserializer branch July 1, 2023 19:56
aajtodd added a commit that referenced this pull request Mar 11, 2024
* feat: identity API upstream changes (#864)
* track upstream codegen changes (#879)
* track upstream IdentityProvider and Attributes changes (#881)
* add base class for credentials config (#883)

BREAKING CHANGE: `CredentialsProvider` method name and signature changed. `signer` property removed from service client config in favor of `authSchemes` override.
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.

3 participants