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

extend automatic serialization support for distinct in Nim 2 #93

Merged
merged 1 commit into from
Jul 3, 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
7 changes: 5 additions & 2 deletions json_serialization/writer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ proc writeValue*(w: var JsonWriter, value: auto) {.gcsafe, raises: [IOError].} =
elif value is (seq or array or openArray):
w.writeArray(value)

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

type Flavor = JsonWriter.Flavor
Expand All @@ -364,7 +364,10 @@ proc writeValue*(w: var JsonWriter, value: auto) {.gcsafe, raises: [IOError].} =
const typeName = typetraits.name(type value)
{.error: "Please override writeValue for the " & typeName & " type (or import the module where the override is provided)".}

writeRecordValue(w, value)
when value is distinct:
writeRecordValue(w, distinctBase(value, recursive = false))
else:
writeRecordValue(w, value)
else:
const typeName = typetraits.name(value.type)
{.fatal: "Failed to convert to JSON an unsupported type: " & typeName.}
Expand Down