fix #17383: json.%,to and jsonutils.formJson,toJson now works with uint|uint64 (#17389) [backport:1.2]
* fix #17383: json.%,to and jsonutils.formJson,toJson now works with uint|uint64 * fixup * fix for js
This commit is contained in:
parent
cfe2f126e5
commit
895a40d1ac
4 changed files with 56 additions and 6 deletions
|
|
@ -304,7 +304,10 @@ proc `%`*(s: string): JsonNode =
|
|||
|
||||
proc `%`*(n: uint): JsonNode =
|
||||
## Generic constructor for JSON data. Creates a new `JInt JsonNode`.
|
||||
result = JsonNode(kind: JInt, num: BiggestInt(n))
|
||||
if n > cast[uint](int.high):
|
||||
result = newJRawNumber($n)
|
||||
else:
|
||||
result = JsonNode(kind: JInt, num: BiggestInt(n))
|
||||
|
||||
proc `%`*(n: int): JsonNode =
|
||||
## Generic constructor for JSON data. Creates a new `JInt JsonNode`.
|
||||
|
|
@ -312,7 +315,10 @@ proc `%`*(n: int): JsonNode =
|
|||
|
||||
proc `%`*(n: BiggestUInt): JsonNode =
|
||||
## Generic constructor for JSON data. Creates a new `JInt JsonNode`.
|
||||
result = JsonNode(kind: JInt, num: BiggestInt(n))
|
||||
if n > cast[BiggestUInt](BiggestInt.high):
|
||||
result = newJRawNumber($n)
|
||||
else:
|
||||
result = JsonNode(kind: JInt, num: BiggestInt(n))
|
||||
|
||||
proc `%`*(n: BiggestInt): JsonNode =
|
||||
## Generic constructor for JSON data. Creates a new `JInt JsonNode`.
|
||||
|
|
@ -1055,8 +1061,16 @@ when defined(nimFixedForwardGeneric):
|
|||
dst = jsonNode.copy
|
||||
|
||||
proc initFromJson[T: SomeInteger](dst: var T; jsonNode: JsonNode, jsonPath: var string) =
|
||||
verifyJsonKind(jsonNode, {JInt}, jsonPath)
|
||||
dst = T(jsonNode.num)
|
||||
when T is uint|uint64:
|
||||
case jsonNode.kind
|
||||
of JString:
|
||||
dst = T(parseBiggestUInt(jsonNode.str))
|
||||
else:
|
||||
verifyJsonKind(jsonNode, {JInt}, jsonPath)
|
||||
dst = T(jsonNode.num)
|
||||
else:
|
||||
verifyJsonKind(jsonNode, {JInt}, jsonPath)
|
||||
dst = cast[T](jsonNode.num)
|
||||
|
||||
proc initFromJson[T: SomeFloat](dst: var T; jsonNode: JsonNode; jsonPath: var string) =
|
||||
verifyJsonKind(jsonNode, {JInt, JFloat}, jsonPath)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue