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:Getting Incorrect Results when Decoding #19549

Closed
xiusin opened this issue Oct 11, 2023 · 2 comments · Fixed by #19579
Closed

json2:Getting Incorrect Results when Decoding #19549

xiusin opened this issue Oct 11, 2023 · 2 comments · Fixed by #19579
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules.

Comments

@xiusin
Copy link
Contributor

xiusin commented Oct 11, 2023

Describe the bug

module cache

import json
import x.json2

pub struct Test[T] {
	data T
}

pub struct SubTest {
pub mut:
	a1 string
	a2 u64
}

fn test_json() {
	test := Test[SubTest]{
		data: SubTest{
			a1: 'xiusin'
			a2: 12
		}
	}

	str := json.encode(test)

	stru := json.decode(Test[SubTest], str)!

	stru1 := json2.decode[Test[SubTest]](str)!

	dump(stru)
	dump(stru1)
}



// result
[/Users/xiusin/CLionProjects/cache/src/bug_test.v:30] stru: cache.Test[cache.SubTest]{
    data: cache.SubTest{
        a1: 'xiusin'
        a2: 12
    }
}
[/Users/xiusin/CLionProjects/cache/src/bug_test.v:31] stru1: cache.Test[cache.SubTest]{
    data: cache.SubTest{
        a1: ''
        a2: 0
    }
}

Reproduction Steps

as above

Expected Behavior

cache.Test[cache.SubTest]{
    data: cache.SubTest{
        a1: 'xiusin'
        a2: 12
    }
}

Current Behavior

cache.Test[cache.SubTest]{
    data: cache.SubTest{
        a1: ''
        a2: 0
    }
}

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.2 37e5616

Environment details (OS name and version, etc.)

V full version: V 0.4.2 b9a1b0c.37e5616
OS: macos, macOS, 13.5.1, 22G90
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz

getwd: /Users/xiusin
vexe: /opt/v/v
vexe mtime: 2023-10-10 06:10:22

vroot: OK, value: /opt/v
VMODULES: OK, value: /Users/xiusin/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.23.0
Git vroot status: 0.4-634-g37e5616b
.git/config present: true

CC version: Apple clang version 14.0.0 (clang-1400.0.29.202)
thirdparty/tcc status: thirdparty-macos-amd64 46662e20-dirty

Note

You can vote for this issue using the 👍 reaction. More votes increase the issue's priority for developers.

Take into account that only the 👍 reaction counts as a vote.
Only reactions to the issue itself will be counted as votes, not comments.

@xiusin xiusin added the Bug This tag is applied to issues which reports bugs. label Oct 11, 2023
@ArtemkaKun ArtemkaKun added Generics[T] Bugs/feature requests, that are related to the V generics. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. labels Oct 11, 2023
@xiusin
Copy link
Contributor Author

xiusin commented Oct 11, 2023

@ArtemkaKun After examining the source code, it appears that the decoding of structure fields has not been implemented yet.

@ArtemkaKun
Copy link
Contributor

Ok, good to know

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. Generics[T] Bugs/feature requests, that are related to the V generics. 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