mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
json: support field &Type
(#17655)
This commit is contained in:
parent
5eb331ed89
commit
b345d77805
3 changed files with 86 additions and 54 deletions
28
vlib/json/json_encode_with_ptr_test.v
Normal file
28
vlib/json/json_encode_with_ptr_test.v
Normal file
|
@ -0,0 +1,28 @@
|
|||
import json
|
||||
|
||||
struct User {
|
||||
name string
|
||||
}
|
||||
|
||||
struct MyStruct {
|
||||
user &User //
|
||||
users map[string]User
|
||||
users2 map[string]&User
|
||||
}
|
||||
|
||||
fn test_json_encode_with_ptr() {
|
||||
user := User{
|
||||
name: 'foo'
|
||||
}
|
||||
data := MyStruct{
|
||||
user: &user
|
||||
users: {
|
||||
'keyfoo': user
|
||||
}
|
||||
users2: {
|
||||
'keyfoo': &user
|
||||
}
|
||||
}
|
||||
|
||||
assert json.encode(data) == '{"user":{"name":"foo"},"users":{"keyfoo":{"name":"foo"}},"users2":{"keyfoo":{"name":"foo"}}}'
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue