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

builtin, cgen: support FieldData.unaliased_typ, use it for generalising x.json2 (able to encode type aliased struct fields) (#16469)

This commit is contained in:
Hitalo Souza
2022-11-20 06:18:14 -03:00
committed by GitHub
parent 06764bc559
commit 45854882b9
16 changed files with 981 additions and 317 deletions

View File

@ -371,20 +371,23 @@ fn test_errors() {
}
type ID = string
type GG = int
struct Message {
id ID
ij GG
}
fn test_decode_alias_struct() {
msg := json.decode(Message, '{"id": "118499178790780929"}')!
// hacky way of comparing aliased strings
assert msg.id.str() == '118499178790780929'
assert msg.ij.str() == '0'
}
fn test_encode_alias_struct() {
expected := '{"id":"118499178790780929"}'
msg := Message{'118499178790780929'}
expected := '{"id":"118499178790780929","ij":999998888}'
msg := Message{'118499178790780929', 999998888}
out := json.encode(msg)
assert out == expected
}