1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

json: fix error for json encoding sumtype value (#13248)

This commit is contained in:
yuyi
2022-01-22 23:55:19 +08:00
committed by GitHub
parent 839ae6b2e4
commit e66e35ced1
2 changed files with 25 additions and 1 deletions

View File

@ -430,3 +430,27 @@ fn test_omit_empty() {
// println('omitempty:')
// println(json.encode_pretty(foo))
}
struct Asdasd {
data GamePacketData
}
type GamePacketData = GPEquipItem | GPScale
struct GPScale {
value f32
}
struct GPEquipItem {
name string
}
fn create_game_packet(data &GamePacketData) string {
return json.encode(data)
}
fn test_encode_sumtype_defined_ahead() {
ret := create_game_packet(&GamePacketData(GPScale{}))
println(ret)
assert ret == '{"value":0,"_type":"GPScale"}'
}