mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
encoding/json: Properly marshal #no_nil unions
Previously the first variant of a `#no_nil` would always be output as `null`, and following variants would be treated as the wrong type.
This commit is contained in:
@@ -469,12 +469,15 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:
|
|||||||
case: panic("Invalid union tag type")
|
case: panic("Invalid union tag type")
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.data == nil || tag == 0 {
|
if !info.no_nil {
|
||||||
io.write_string(w, "null") or_return
|
if tag == 0 {
|
||||||
} else {
|
io.write_string(w, "null") or_return
|
||||||
id := info.variants[tag-1].id
|
return nil
|
||||||
return marshal_to_writer(w, any{v.data, id}, opt)
|
}
|
||||||
|
tag -= 1
|
||||||
}
|
}
|
||||||
|
id := info.variants[tag].id
|
||||||
|
return marshal_to_writer(w, any{v.data, id}, opt)
|
||||||
|
|
||||||
case runtime.Type_Info_Enum:
|
case runtime.Type_Info_Enum:
|
||||||
if !opt.use_enum_names || len(info.names) == 0 {
|
if !opt.use_enum_names || len(info.names) == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user