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

veb.Context VS x.json2.Any #23777

Open
vodish opened this issue Feb 20, 2025 · 6 comments
Open

veb.Context VS x.json2.Any #23777

vodish opened this issue Feb 20, 2025 · 6 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@vodish
Copy link

vodish commented Feb 20, 2025

Describe the bug

Image

test code
https://play.vlang.io/p/0fe8989740

module main

import veb
import x.json2

fn main() {
	mut ctx := veb.Context{}
	
	ctx.json(map[string]json2.Any) // err
}

err

cgen error: json: can not decode `x.json2.Any` sumtype,
too many numeric types (conflict of `f64` and `f32`),
you can try to use alias for `f32` or compile v with `json_no_inline_sumtypes` flag

Reproduction Steps

conflict

Expected Behavior

conflict

Current Behavior

conflict

Possible Solution

No response

Additional Information/Context

No response

V version

0.4.9

Environment details (OS name and version, etc.)

wsl (ubuntu)

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.

@vodish vodish added the Bug This tag is applied to issues which reports bugs. label Feb 20, 2025
Copy link

Connected to Huly®: V_0.6-22188

@vodish
Copy link
Author

vodish commented Feb 21, 2025

solution

https://github.com/vlang/v/blob/master/vlib/veb/context.v

// add import
import x.json2

// add method
pub fn (mut ctx Context) json2[T](j T) Result {
	json_s := json2.encode(j)
	return ctx.send_response_to_client('application/json', json_s)
}

зы. I don't know how to make a pull request, sorry))

@jorgeluismireles
Copy link

I did a search in v/vlib folder for occurrences of import x. and found that apart tests and other x folders like x.crypto no standard v code imports modules from x. I assume (correct me if I was wrong) this is by design so json2 could be used by veb until moves from x to the standard lib. By now we programmers could make our own Context based in veb.Context and add here this json2 function.

@vodish
Copy link
Author

vodish commented Feb 21, 2025

@jorgeluismireles
that's what I did for the local Context structure.
as temp solution

@JalonSolov
Copy link
Contributor

The intent is for x.json2 to completely replace json, once it's finished. Currently, x.json2 does some things json doesn't, but there are things json does that x.json2 doesn't. Until x.json2 does everything json does and more, they will stay separate.

@vodish
Copy link
Author

vodish commented Feb 21, 2025

The problem is in the Value Type, not in the method implementation

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.
Projects
None yet
Development

No branches or pull requests

3 participants