Fix json.to for float fields that are not present (#21695)

(cherry picked from commit 418e54452b)
This commit is contained in:
Yardanico
2023-04-21 07:11:30 +03:00
committed by narimiran
parent 064ed4846d
commit 4071b3fad8

View File

@@ -1121,6 +1121,7 @@ when defined(nimFixedForwardGeneric):
dst = cast[T](jsonNode.num)
proc initFromJson[T: SomeFloat](dst: var T; jsonNode: JsonNode; jsonPath: var string) =
verifyJsonKind(jsonNode, {JInt, JFloat}, jsonPath)
if jsonNode.kind == JString:
case jsonNode.str
of "nan":
@@ -1136,7 +1137,6 @@ when defined(nimFixedForwardGeneric):
dst = T(b)
else: raise newException(JsonKindError, "expected 'nan|inf|-inf', got " & jsonNode.str)
else:
verifyJsonKind(jsonNode, {JInt, JFloat}, jsonPath)
if jsonNode.kind == JFloat:
dst = T(jsonNode.fnum)
else: