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

allow serializing distinct arrays #97

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions json_serialization/writer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,12 @@ proc writeValue*(w: var JsonWriter, value: auto) {.gcsafe, raises: [IOError].} =
# to avoid the allocation here:
append $value

elif value is (seq or array or openArray):
w.writeArray(value)
elif value is (seq or array or openArray) or
(value is distinct and distinctBase(value) is (seq or array or openArray)):
when value is distinct:
w.writeArray(distinctBase value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't that ignore an override of writeValue if we have:

  • A = seq[int] (base)
  • B = distinct A
  • C = distinct B

if we write C and have a custom writeValue on B?

distinctBase by default applies recursively, so distinctBase(C) is A not B.

else:
w.writeArray(value)

elif value is (distinct or object or tuple):
mixin flavorUsesAutomaticObjectSerialization
Expand Down