File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -839,7 +839,7 @@ fn (mut decoder Decoder) decode_enum[T](mut val T) ! {
839839 decoder.decode_error ('Number value: `${result} ` does not match any field in enum: ${typeof(val).name} ' )!
840840 } else if enum_info.value_kind == .string {
841841 mut result := ''
842- unsafe { decoder.decode_value (mut result)! }
842+ decoder.decode_string (mut result)!
843843
844844 $for value in T.values {
845845 if value.name == result {
Original file line number Diff line number Diff line change @@ -93,3 +93,15 @@ fn test_invalid_decode_fails() {
9393 }
9494 }
9595}
96+
97+ fn test_map_string_enum_decode () {
98+ m := json.decode[map [string ]Bar]('{"foo": "a", "bar": "b", "baz": "c"}' )!
99+ assert m['foo' ] == .a
100+ assert m['bar' ] == .b
101+ assert m['baz' ] == .c
102+
103+ m2 := json.decode[map [string ]Bar]('{"x": 0, "y": 1, "z": 10}' )!
104+ assert m2 ['x' ] == .a
105+ assert m2 ['y' ] == .b
106+ assert m2 ['z' ] == .c
107+ }
You can’t perform that action at this time.
0 commit comments