wip ref fixes

This commit is contained in:
Zahary Karadjov 2019-11-25 20:46:14 +02:00
parent 88b79e2300
commit ee4795cf29
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 14 additions and 1 deletions

View File

@ -2,6 +2,9 @@ import
typetraits,
faststreams/output_stream, serialization, json
import
stew/shims/macros
type
JsonWriterState = enum
RecordExpected
@ -136,7 +139,17 @@ proc writeValue*(w: var JsonWriter, value: auto) =
if value == nil:
append "null"
else:
writeValue(w, value[])
when value[] is object:
w.beginRecord(type(value))
type RecordType = type value
value.enumInstanceSerializedFields(fieldName, field):
type FieldType = type field
w.writeFieldName(fieldName)
w.writeFieldIMPL(FieldTag[RecordType, fieldName, FieldType], field, value)
w.state = AfterField
w.endRecord()
else:
writeValue(w, value[])
elif value is string|cstring:
append '"'