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
|
|
@ -77,8 +77,7 @@
|
||||||
initialization with a small (< 30000) seed. Use `-d:nimLegacyRandomInitRand` to restore
|
initialization with a small (< 30000) seed. Use `-d:nimLegacyRandomInitRand` to restore
|
||||||
previous behavior for a transition time, see PR #17467.
|
previous behavior for a transition time, see PR #17467.
|
||||||
|
|
||||||
- `jsonutils` now serializes/deserializes holey enums as regular enums (via `ord`) instead of as strings.
|
- With `-d:nimPreviewJsonutilsHoleyEnum`, `jsonutils` 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. `toJson` now serializes `JsonNode`
|
||||||
Use `-d:nimLegacyJsonutilsHoleyEnum` for a transition period. `toJson` now serializes `JsonNode`
|
|
||||||
as is via reference (without a deep copy) instead of treating `JsonNode` as a regular ref object,
|
as is via reference (without a deep copy) instead of treating `JsonNode` as a regular ref object,
|
||||||
this can be customized via `jsonNodeMode`.
|
this can be customized via `jsonNodeMode`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -298,6 +298,10 @@ proc jsonTo*(b: JsonNode, T: typedesc, opt = Joptions()): T =
|
||||||
proc toJson*[T](a: T, opt = initToJsonOptions()): JsonNode =
|
proc toJson*[T](a: T, opt = initToJsonOptions()): JsonNode =
|
||||||
## serializes `a` to json; uses `toJsonHook(a: T)` if it's in scope to
|
## serializes `a` to json; uses `toJsonHook(a: T)` if it's in scope to
|
||||||
## customize serialization, see strtabs.toJsonHook for an example.
|
## 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)
|
when compiles(toJsonHook(a)): result = toJsonHook(a)
|
||||||
elif T is object | tuple:
|
elif T is object | tuple:
|
||||||
when T is object or isNamedTuple(T):
|
when T is object or isNamedTuple(T):
|
||||||
|
|
@ -328,7 +332,7 @@ proc toJson*[T](a: T, opt = initToJsonOptions()): JsonNode =
|
||||||
elif T is enum:
|
elif T is enum:
|
||||||
case opt.enumMode
|
case opt.enumMode
|
||||||
of joptEnumOrd:
|
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)
|
else: toJson($a, opt)
|
||||||
of joptEnumSymbol:
|
of joptEnumSymbol:
|
||||||
when T is OrdinalEnum:
|
when T is OrdinalEnum:
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,12 @@ hint("Processing", off)
|
||||||
# switch("hint", "ConvFromXtoItselfNotNeeded")
|
# switch("hint", "ConvFromXtoItselfNotNeeded")
|
||||||
# switch("warningAsError", "InheritFromException") # would require fixing a few tests
|
# switch("warningAsError", "InheritFromException") # would require fixing a few tests
|
||||||
|
|
||||||
# experimental API's are enabled in testament, refs https://github.com/timotheecour/Nim/issues/575
|
# experimental APIs are enabled in testament, refs https://github.com/timotheecour/Nim/issues/575
|
||||||
# sync with `kochdocs.docDefines` or refactor.
|
# sync with `kochdocs.docDefines` or refactor.
|
||||||
switch("define", "nimExperimentalAsyncjsThen")
|
switch("define", "nimExperimentalAsyncjsThen")
|
||||||
switch("define", "nimExperimentalLinenoiseExtra")
|
switch("define", "nimExperimentalLinenoiseExtra")
|
||||||
|
|
||||||
|
# preview APIs are expected to be the new default in upcoming versions
|
||||||
switch("define", "nimPreviewFloatRoundtrip")
|
switch("define", "nimPreviewFloatRoundtrip")
|
||||||
switch("define", "nimPreviewDotLikeOps")
|
switch("define", "nimPreviewDotLikeOps")
|
||||||
|
switch("define", "nimPreviewJsonutilsHoleyEnum")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue