1
0
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:
Felipe Pena
2023-04-10 13:50:35 -03:00
committed by GitHub
parent 624f1592a8
commit 319ad5bae2
2 changed files with 36 additions and 4 deletions

View 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
}