mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
Fix json.to for float fields that are not present (#21695)
(cherry picked from commit 418e54452b)
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user