mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
@@ -1120,7 +1120,10 @@ when defined(nimFixedForwardGeneric):
|
||||
|
||||
proc initFromJson[T](dst: var Option[T]; jsonNode: JsonNode; jsonPath: var string) =
|
||||
if jsonNode != nil and jsonNode.kind != JNull:
|
||||
dst = some(default(T))
|
||||
when T is ref:
|
||||
dst = some(new(T))
|
||||
else:
|
||||
dst = some(default(T))
|
||||
initFromJson(dst.get, jsonNode, jsonPath)
|
||||
|
||||
macro assignDistinctImpl[T: distinct](dst: var T;jsonNode: JsonNode; jsonPath: var string) =
|
||||
|
||||
16
tests/stdlib/toptions.nim
Normal file
16
tests/stdlib/toptions.nim
Normal file
@@ -0,0 +1,16 @@
|
||||
discard """
|
||||
output: '''{"foo":{"test":"123"}}'''
|
||||
"""
|
||||
|
||||
import json, options
|
||||
|
||||
type
|
||||
Foo = ref object
|
||||
test: string
|
||||
Test = object
|
||||
foo: Option[Foo]
|
||||
|
||||
let js = """{"foo": {"test": "123"}}"""
|
||||
let parsed = parseJson(js)
|
||||
let a = parsed.to(Test)
|
||||
echo $(%*a)
|
||||
Reference in New Issue
Block a user