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

json: fix f32 is not struct

This commit is contained in:
Delyan Angelov 2020-05-31 14:17:20 +03:00
parent faf3248e98
commit f1f6fb1a9f
2 changed files with 7 additions and 3 deletions

View File

@ -3,18 +3,22 @@ import json
struct Employee {
name string
age int
salary f32
}
fn test_simple() {
x := Employee{'Peter', 28}
x := Employee{'Peter', 28, 95000.5}
s := json.encode(x)
assert s == '{"name":"Peter","age":28}'
eprintln('Employee x: $s')
assert s == '{"name":"Peter","age":28,"salary":95000.5}'
y := json.decode(Employee, s) or {
assert false
Employee{}
}
eprintln('Employee y: $y')
assert y.name == 'Peter'
assert y.age == 28
assert y.salary == 95000.5
}
struct User2 {

View File

@ -22,7 +22,7 @@ fn (mut g Gen) gen_json_for_type(typ table.Type) {
mut enc := strings.new_builder(100)
sym := g.table.get_type_symbol(typ)
styp := g.typ(typ)
if sym.name in ['int', 'string', 'bool'] {
if sym.name in ['int', 'string', 'bool', 'f32'] {
return
}
if sym.kind == .array {