You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried a quick (naive) implementation, which at first failed because fieldPairs does not work with refs. I tried my own wrapper for refs, but then that fails somewhere in the hasCustomPragma macro (unexpected node type nnkHiddenDeRef). Here was my attempt:
diff --git a/src/samson.nim b/src/samson.nim
index b11589e..1b41a83 100644
--- a/src/samson.nim+++ b/src/samson.nim@@ -14,7 +14,7 @@ export errors
type
- PlainObject = (object) and+ PlainObject = (object|ref object) and
(not (Option|Either|Table|OrderedTable|HashSet|OrderedSet|DateTime|Time))
SupportedIntegerTypes = int8|int16|int32|int|int64|uint8|uint16|uint32
@@ -302,6 +302,10 @@ proc dateTimeFromJson(tree: JTree, idx: JnodeIdx,
else:
result = parseTime(tree.nodes[idx].strVal, f, local())
+iterator fieldPairs[T: ref object](o: var T): (string, var typed) + for f, v in fieldPairs(o[]):+ yield (f, v)+
proc fromJsonImpl(tree: JTree, idx: JNodeIdx, T: typedesc): T =
template error {.used.} =
schemaError(T, `$`(tree, idx))
I usually avoid reference types in Nim and I'm not sure samson should support it. Typically there shouldn't be a reason to use a ref type for serialization/deserialization.
I think you might have hit a compiler bug with you solution, and it seems like there are more compiler issues related to fieldPairs and ref types (I just reported nim-lang/Nim#12523).
Is it planned to implement support for unmarshalling to reference (
ref object
) types? Example based on the README:Currently this fails with : "Unsupported type: User".
The text was updated successfully, but these errors were encountered: