mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
json: fix json.decode with map alias (#17925)
This commit is contained in:
26
vlib/json/json_alias_test.v
Normal file
26
vlib/json/json_alias_test.v
Normal file
@ -0,0 +1,26 @@
|
||||
import json
|
||||
|
||||
pub struct User {
|
||||
name string
|
||||
age int
|
||||
height f64
|
||||
}
|
||||
|
||||
type Users = map[string]User
|
||||
|
||||
const json_users = '{
|
||||
"tom": { "name": "Tom", "age": 45, "height": 1.97 },
|
||||
"martin": { "name": "Martin", "age": 40, "height": 1.8 }
|
||||
}'
|
||||
|
||||
fn test_alias_with_map() {
|
||||
a := json.decode(map[string]User, json_users)!
|
||||
b := json.decode(Users, json_users)!
|
||||
|
||||
assert Users(a) == b
|
||||
|
||||
c := json.encode(a)
|
||||
d := json.encode(b)
|
||||
|
||||
assert c == d
|
||||
}
|
Reference in New Issue
Block a user