Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions json_serialization/writer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,7 @@ proc writeValue*[V: not void](w: var JsonWriter, value: V) {.raises: [IOError].}
elif value is SomeFloat:
autoSerializeCheck(Flavor, SomeFloat, typeof(value)):
w.streamElement(s):
# TODO Implement writeText for floats
# to avoid the allocation here:
s.write $value
s.writeText value

elif value is seq or(value is distinct and distinctBase(value) is seq):
autoSerializeCheck(Flavor, seq, typeof(value)):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ suite "toJson tests":
"".toJson == "\"\""
"abc".toJson == "\"abc\""

test "float":
Json.roundtripTest 1.23, "1.23"
Json.roundtripTest 1.23'f32, "1.23"
Json.roundtripTest 1.23'f64, "1.23"

test "enums":
Json.roundtripTest x0, "\"x0\""
Json.roundtripTest x1, "\"x1\""
Expand Down