Compare commits

...

2 Commits

Author SHA1 Message Date
Andreas Rumpf
d04d14e9fe Merge branch 'devel' into pr_best_efforts 2025-10-08 08:08:23 +02:00
ringabout
c64e45d363 -d:nimPreviewJsonutilsHoleyEnum becomes the default 2024-10-03 21:55:20 +08:00
3 changed files with 8 additions and 10 deletions

View File

@@ -3,6 +3,8 @@
## Changes affecting backward compatibility
- `-d:nimPreviewJsonutilsHoleyEnum` becomes the default, `jsonutils` now can serialize/deserialize
holey enums as regular enums (via `ord`) instead of as strings.
- `-d:nimPreviewFloatRoundtrip` becomes the default. `system.addFloat` and `system.$` now can produce string representations of
floating point numbers that are minimal in size and possess round-trip and correct
rounding guarantees (via the

View File

@@ -301,10 +301,8 @@ 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.
## `toJson` serialize/deserialize holey enums as regular enums (via `ord`)
## instead of as strings.
when compiles(toJsonHook(a, opt)): result = toJsonHook(a, opt)
elif compiles(toJsonHook(a)): result = toJsonHook(a)
elif T is object | tuple:
@@ -336,14 +334,13 @@ proc toJson*[T](a: T, opt = initToJsonOptions()): JsonNode =
elif T is enum:
case opt.enumMode
of joptEnumOrd:
when T is Ordinal or defined(nimPreviewJsonutilsHoleyEnum): %(a.ord)
else: toJson($a, opt)
result = %(a.ord)
of joptEnumSymbol:
when T is OrdinalEnum:
toJson(symbolName(a), opt)
result = toJson(symbolName(a), opt)
else:
toJson($a, opt)
of joptEnumString: toJson($a, opt)
result = toJson($a, opt)
of joptEnumString: result = toJson($a, opt)
elif T is Ordinal: result = %(a.ord)
elif T is cstring: (if a == nil: result = newJNull() else: result = % $a)
else: result = %a

View File

@@ -33,7 +33,6 @@ hint("Processing", off)
# preview APIs are expected to be the new default in upcoming versions
#switch("define", "nimPreviewDotLikeOps") # deprecated?
switch("define", "nimPreviewJsonutilsHoleyEnum")
switch("define", "nimPreviewHashRef")
switch("define", "nimPreviewRangeDefault")
switch("define", "nimPreviewNonVarDestructor")