From f1f6fb1a9f35300e3d8d69552a3a16209f7fa081 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 31 May 2020 14:17:20 +0300 Subject: [PATCH] json: fix `f32 is not struct` --- vlib/json/json_test.v | 8 ++++++-- vlib/v/gen/json.v | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/vlib/json/json_test.v b/vlib/json/json_test.v index 24b2584430..55c48830a1 100644 --- a/vlib/json/json_test.v +++ b/vlib/json/json_test.v @@ -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 { diff --git a/vlib/v/gen/json.v b/vlib/v/gen/json.v index 522b27d6d4..9e35abd478 100644 --- a/vlib/v/gen/json.v +++ b/vlib/v/gen/json.v @@ -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 {