It parses the first value fine, but the second one it just appears to skip it:
this is a minimul standalone example:
objects := `
{
"id": "1",
"objects": [
{
"name": "object 1",
"type": "a"
},
{
"name": "object 2",
"type": "b"
}
],
}
`
JsonFile :: struct {
id: string,
objects: []Obj,
}
Obj :: struct {
name: string,
type: Type,
}
Type :: enum {
TypeInvalid,
TypeA,
TypeB,
}
main :: proc() {
json.set_user_unmarshalers(new(map[typeid]json.User_Unmarshaler))
reg_err := json.register_user_unmarshaler(Type, type_unmarshal)
json_file: JsonFile
err := json.unmarshal_string(objects, &json_file)
for obj in json_file.objects {
fmt.println(obj)
}
}
type_unmarshal :: proc(p: ^json.Parser, v: any) -> json.Unmarshal_Error {
token := p.curr_token.text
switch token {
case `"a"`:
(^Type)(v.data)^ = .TypeA
case `"b"`:
(^Type)(v.data)^ = .TypeB
case:
(^Type)(v.data)^ = .TypeInvalid
}
return .None
}