Open VitSimon opened 8 months ago
I have altered examples\json.v locally to test it on smaller footprint. I can verify there is the same behavior so it is independent on vweb package.
Hello, does there is any update to this issue? Thanks for reply.
Hey @VitSimon, thanks for reporting the issue! Can you provide a self-contained example that can be used to reproduce the issue? This would simplify looking into it and speed up a fix. For more complex issues, please provide a repo with the smallest sample that reproduces the bug.
@ttytm Hello, example is prepared here: https://github.com/VitSimon/IssueAttachments/tree/vlang-v-20600 (based on example file in vlang repository, only simply altered for my scenario) Produced output: [{"Address":{"addr":""},"name":"Frodo","age":25,"is_registered":true},{"Address":{"addr":""},"name":"Bobby","age":10,"is_registered":false}] Predicted output to be produced: [{"addr":"","name":"Frodo","age":25,"is_registered":true},{"addr":"","name":"Bobby","age":10,"is_registered":false}]
Describe the bug
Hi,
I have tried code in Reproduction Steps and I think there is bad processing of anonymous members (composition) of type structure in structures. JSON text is providing another extra level for non named member of type struct.
In comparison to Golang there is not any extra level in this case.
If I need to have all values on same level, what I need to do more to reach it? Thanks for advice.
Reproduction Steps
with vweb module
and getting this structure in browser:
raw text:
Does it is correct?
Expected Behavior
raw text:
Current Behavior
and getting this structure in browser:
raw text:
Possible Solution
I am surprised by:
coding structure ArticlePlus to:
There is non named property so I thogut it should be fully embedded on same level as rest of struct members. Instead of it That member is named as same as given type and its data are inside another brackets. When I give a name to anonymous member, like:
struct ArticlePlus { articleData Article perex string }
then json is changed:
When I compare it to golang, then there is no sub level for composition of structures.
Additional Information/Context
No response
V version
0.4.4 629bae4, timestamp: 2024-01-20 12:15:58
Environment details (OS name and version, etc.)
Microsoft Windows [Version 10.0.19045.3930], x64