Skip to content

Add @preserveKeyOrder trait#245

Merged
a-morales merged 3 commits intomainfrom
add-preserveKeyOrder-trait
Sep 2, 2025
Merged

Add @preserveKeyOrder trait#245
a-morales merged 3 commits intomainfrom
add-preserveKeyOrder-trait

Conversation

@a-morales
Copy link
Copy Markdown
Contributor

Adding a new trait that is applicable to maps that should denote that the keys should be serialized/deserialized in order.

Comment on lines +7 to +9
@trait(
selector: ":is(map)"
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we also allow this on member shapes targeting map shapes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That makes sense and I'll add the selector. Should we also allow this for Document shapes?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah now that is a good question. It's tricky because document doesn't necessarily indicate an Object.. Do we currently have support for preserving ordering in documents in smithy4s? Or use it in the dynamic module? I think if we don't already have it, then let's leave support for it out for now and we can always add it later if we decide to

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a comment to the PR that implements this in smithy4s https://github.com/disneystreaming/smithy4s/pull/1820/files#diff-723646fa221b5ad4799cce9b4e34f0eb3411e577fecfd88f5ce96b58bffdbb5bR508. The SchemaVisitorJCodec does use the preserveMapOrder boolean when handling document objects.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay interesting, I guess that makes sense from the perspective of a user using the smithy4s-json module. In that case, maybe we should allow this trait on Document and it will only have applicability in the case of objects.. @kubukoz thoughts?

Copy link
Copy Markdown
Member

@kubukoz kubukoz Aug 28, 2025

Choose a reason for hiding this comment

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

Can't see anything problematic with it at the moment...

let's just make sure it's supported in the document codecs as well. Encode-side too, right? ok I see that in the docs of the trait, makes sense to me

Copy link
Copy Markdown
Member

@kubukoz kubukoz left a comment

Choose a reason for hiding this comment

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

suggestion: compliance tests for this?

@lewisjkl
Copy link
Copy Markdown
Contributor

Mentioned this earlier, but so we don't forget, we'll need to add the new trait here:

@lewisjkl
Copy link
Copy Markdown
Contributor

lewisjkl commented Aug 28, 2025

Aside: I guess we can technically add support for this trait on smithy4s 0.18 as well and deprecate the current methods for "preserveSortOrder" we should discuss on discord perhaps

@a-morales a-morales merged commit cc65e49 into main Sep 2, 2025
3 checks passed
@kubukoz kubukoz deleted the add-preserveKeyOrder-trait branch September 3, 2025 11:10
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