Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x.json2 can not decode properly a struct with a fixed array field #21150

Closed
spytheman opened this issue Mar 30, 2024 · 1 comment · Fixed by #21163
Closed

x.json2 can not decode properly a struct with a fixed array field #21150

spytheman opened this issue Mar 30, 2024 · 1 comment · Fixed by #21163
Labels
Bug This tag is applied to issues which reports bugs. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules.

Comments

@spytheman
Copy link
Member

spytheman commented Mar 30, 2024

V doctor:

V full version: V 0.4.5 872bcbc.13a2efd
OS: linux, Ubuntu 20.04.6 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz

getwd: /space/v/oo
vexe: /space/v/oo/v
vexe mtime: 2024-03-30 15:59:29

vroot: OK, value: /space/v/oo
VMODULES: OK, value: /home/delian/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.42.0
Git vroot status: weekly.2024.13-57-g13a2efd6
.git/config present: true

CC version: cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
thirdparty/tcc status: thirdparty-linux-amd64 40e5cbb5

What did you do?
v -g -o vdbg cmd/v && vdbg bug_fixed_array_json2.v

import x.json2
struct Pos { pos [3]f64 }
input := '{"pos": [0.5, 0.0, 0.5]}'
p := json2.decode[Pos](input)!
dump(p)

What did you expect to see?

the pos field should be: pos: [0.5, 0.0, 0.5]

What did you see instead?

[bug_fixed_array_json2.v:5] p: Pos{
    pos: [0.0, 0.0, 0.0]
}

The equivalent program, using json works:

import json
struct Pos { pos [3]f64 }
input := '{"pos": [0.5, 0.0, 0.5]}'
p := json.decode(Pos, input)!
dump(p)

producing:

[bug_fixed_array_json_working.v:5] p: Pos{
    pos: [0.5, 0.0, 0.5]
}

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. labels Mar 30, 2024
@Delta456
Copy link
Member

Delta456 commented Apr 1, 2024

x.json2 also cannot decode a struct with an int slice.

import x.json2
struct Pos { pos []int }
input := '{"pos": [1, 3, 5]}'
p := json2.decode[Pos](input)!
dump(p)

producing:

v run file.v                                                                                                                                                       ─╯
[file.v:5] p: Pos{
    pos: []
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants