rename nimLegacyJsonutilsHoleyEnum [backport] (#18938)
* enable nimPreviewJsonutilsHoleyEnum [backport] * docuement nimPreviewJsonutilsHoleyEnum
This commit is contained in:
parent
7577ea9e4c
commit
5c4692fad4
3 changed files with 9 additions and 4 deletions
|
|
@ -298,6 +298,10 @@ proc jsonTo*(b: JsonNode, T: typedesc, opt = Joptions()): T =
|
|||
proc toJson*[T](a: T, opt = initToJsonOptions()): JsonNode =
|
||||
## serializes `a` to json; uses `toJsonHook(a: T)` if it's in scope to
|
||||
## customize serialization, see strtabs.toJsonHook for an example.
|
||||
##
|
||||
## .. note:: With `-d:nimPreviewJsonutilsHoleyEnum`, `toJson` now can
|
||||
## serialize/deserialize holey enums as regular enums (via `ord`) instead of as strings.
|
||||
## It is expected that this behavior becomes the new default in upcoming versions.
|
||||
when compiles(toJsonHook(a)): result = toJsonHook(a)
|
||||
elif T is object | tuple:
|
||||
when T is object or isNamedTuple(T):
|
||||
|
|
@ -328,7 +332,7 @@ proc toJson*[T](a: T, opt = initToJsonOptions()): JsonNode =
|
|||
elif T is enum:
|
||||
case opt.enumMode
|
||||
of joptEnumOrd:
|
||||
when T is Ordinal or not defined(nimLegacyJsonutilsHoleyEnum): %(a.ord)
|
||||
when T is Ordinal or defined(nimPreviewJsonutilsHoleyEnum): %(a.ord)
|
||||
else: toJson($a, opt)
|
||||
of joptEnumSymbol:
|
||||
when T is OrdinalEnum:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue