added enum indexed array support to json (#16807)
* added enum indexed array support to json * Added json test * Removed when statement for enum indexed arrays
This commit is contained in:
parent
25745ad195
commit
dde096ffde
2 changed files with 12 additions and 1 deletions
|
|
@ -1103,7 +1103,7 @@ when defined(nimFixedForwardGeneric):
|
||||||
jsonPath.add '['
|
jsonPath.add '['
|
||||||
jsonPath.addInt i
|
jsonPath.addInt i
|
||||||
jsonPath.add ']'
|
jsonPath.add ']'
|
||||||
initFromJson(dst[i], jsonNode[i], jsonPath)
|
initFromJson(dst[i.S], jsonNode[i], jsonPath) # `.S` for enum indexed arrays
|
||||||
jsonPath.setLen originalJsonPathLen
|
jsonPath.setLen originalJsonPathLen
|
||||||
|
|
||||||
proc initFromJson[T](dst: var Table[string,T]; jsonNode: JsonNode; jsonPath: var string) =
|
proc initFromJson[T](dst: var Table[string,T]; jsonNode: JsonNode; jsonPath: var string) =
|
||||||
|
|
|
||||||
11
tests/stdlib/tjson_enum_index.nim
Normal file
11
tests/stdlib/tjson_enum_index.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import json
|
||||||
|
type Test = enum
|
||||||
|
one, two, three, four, five
|
||||||
|
let a = [
|
||||||
|
one: 300,
|
||||||
|
two: 20,
|
||||||
|
three: 10,
|
||||||
|
four: 0,
|
||||||
|
five: -10
|
||||||
|
]
|
||||||
|
doAssert (%* a).to(a.typeof) == a
|
||||||
Loading…
Add table
Add a link
Reference in a new issue