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

json2 is not decoding embedded structs properly #23354

Open
hungrybluedev opened this issue Jan 3, 2025 · 1 comment
Open

json2 is not decoding embedded structs properly #23354

hungrybluedev opened this issue Jan 3, 2025 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs. Modules: x.json2 Bugs related to *only* x.json2 (the pure V implementation)

Comments

@hungrybluedev
Copy link
Member

hungrybluedev commented Jan 3, 2025

V doctor:

V full version: V 0.4.9 7b9b3dd.c50d4ee
OS: macos, macOS, 15.1.1, 24B91
Processor: 10 cpus, 64bit, little endian, Apple M1 Pro

getwd: /Users/subhomoyhaldar/Documents/GitHub/VProjects/Consultation/VHamMLLTest
vexe: /Users/subhomoyhaldar/Documents/GitHub/v-main/v
vexe mtime: 2025-01-02 17:59:31

vroot: OK, value: /Users/subhomoyhaldar/Documents/GitHub/v-main
VMODULES: OK, value: /Users/subhomoyhaldar/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.39.5 (Apple Git-154)
Git vroot status: weekly.2024.53-15-gc50d4ee1
.git/config present: true

CC version: Apple clang version 16.0.0 (clang-1600.0.26.6)
emcc version: N/A
thirdparty/tcc status: thirdparty-macos-arm64 713692d4

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

import x.json2

pub struct Environment {
	vflags string
}

pub struct HistoryEvent {
	Environment
}

pub struct History {
pub mut:
	history_events []HistoryEvent
}

pub struct Classifier {
	History
}

pub fn main() {
	mut cl := Classifier{}
	cl.history_events = [HistoryEvent{}, HistoryEvent{}]
	dump(cl)
	s := json2.encode(cl)
	println(s)

	dcl := json2.decode[Classifier](s)!
	dump(dcl)
}

What did you see?

[src/main.v:23] cl: Classifier{
    History: History{
        history_events: [HistoryEvent{
            Environment: Environment{
                vflags: ''
            }
        }, HistoryEvent{
            Environment: Environment{
                vflags: ''
            }
        }]
    }
}
{"History":{"history_events":[{"Environment":{"vflags":""}},{"Environment":{"vflags":""}}]}}
[src/main.v:28] dcl: Classifier{
    History: History{
        history_events: []
    }
}

What did you expect to see?

Both the dump outputs should be the same. The encoded and decoded structs are different.

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.

Huly®: V_0.6-21785

@hungrybluedev hungrybluedev added the Bug This tag is applied to issues which reports bugs. label Jan 3, 2025
@felipensp
Copy link
Member

felipensp commented Jan 3, 2025

Currently decoding array of custom struct is only implemented on import x.json2.decoder2 as new_json, not x.json2.

@felipensp felipensp added the Modules: x.json2 Bugs related to *only* x.json2 (the pure V implementation) label Jan 3, 2025
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: x.json2 Bugs related to *only* x.json2 (the pure V implementation)
Projects
None yet
Development

No branches or pull requests

2 participants