Skip to content

[json2] Can't decode map[string]SomeEnumStruct #26176

Description

@K1ndWha1e

Describe the bug

Hello! json2 module can't decode multiple values string to map with Enum. See: https://play.vlang.io/p/a83ab61424

Reproduction Steps

import x.json2 as json

enum Foo {
	value1
	value2
}

fn main() {
	a := '{
		"foo1": "value1",
		"foo2": "value2"
	}'

	b := json.decode[map[string]Foo](a) or {
		println(err)
		return
	}

	println(b)
}

Expected Behavior

Successful decoding

Current Behavior

/home/admin/v/vlib/x/json2/decode.v:802: at x__json2__Decoder_decode_map_T_string_main__Foo: RUNTIME ERROR: invalid memory access
/home/admin/v/vlib/x/json2/decode.v:368: by x__json2__Decoder_decode_value_T_Map_string_main__Foo
/home/admin/v/vlib/x/json2/decode.v:291: by x__json2__decode_T_Map_string_main__Foo
/box/code.v:10: by main__main
/tmp/v_60000/code.01KDG5VXART0R6M8VRB2KM99VQ.tmp.c:30995: by main
Exited with error status 255

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.12 9a73766

Environment details (OS name and version, etc.)

Doesn't matter

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions