json2: encode reference fields too (#17058)

This commit is contained in:
Hitalo Souza 2023-04-28 10:24:27 -03:00 committed by GitHub
parent 433208ea7e
commit b0589c645d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 43 deletions

View file

@ -265,6 +265,25 @@ fn test_encode_alias_field() {
assert s == '{"sub":{"a":1}}'
}
struct APrice {}
pub struct Association {
association &Association = unsafe { nil }
price APrice
}
//! FIX: returning null
fn test_encoding_struct_with_pointers() {
value := Association{
association: &Association{
price: APrice{}
}
price: APrice{}
}
// println(value)
assert json.encode(value) == '{"association":{"price":{}},"price":{}}'
}
pub struct City {
mut:
name string

View file

@ -367,21 +367,3 @@ fn test_encode_sumtype_defined_ahead() {
ret := create_game_packet(&GamePacketData(GPScale{}))
assert ret == '{"value":0,"_type":"GPScale"}'
}
struct APrice {}
struct Association {
association &Association = unsafe { nil }
price APrice
}
//! FIX: returning null
fn test_encoding_struct_with_pointers() {
value := Association{
association: &Association{
price: APrice{}
}
price: APrice{}
}
assert json.encode(value) == '{"association":{"price":{}},"price":{}}'
}