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

minjinja does not seem to support serde_json arbitrary-precision number types #641

Closed
janlugt opened this issue Nov 8, 2024 · 2 comments

Comments

@janlugt
Copy link

janlugt commented Nov 8, 2024

I encountered an following issue while reading some JSON from disk, loading it into a serde_json::Value, and trying to create a minijinja context out of it:

let value: serde_json::Value = serde_json::from_str("{\"x\": 42}").unwrap();
println!("value = {}", value.to_string());
let string = serde_json::ser::to_string(&value).unwrap();
println!("string = {}", string);
let context = minijinja::Value::from_serialize(value);
println!("context = {}", context);

This gives the following output:

value = {"x":42}
string = {"x":42}
context = {"x": {"$serde_json::private::Number": "42"}}

I would expect the minijinja::Value to just contain 42 again. If I read the JSON as a specific rust struct, everything works, since in that case the arbitrary-precision number is not used.

Am I holding it wrong, is this expected behavior, or is it a bug?

@mitsuhiko
Copy link
Owner

mitsuhiko commented Nov 10, 2024

This is a serde bug/limitation. I filed an issue a long time ago in the serde repo about it: serde-rs/serde#1463

Not much I can do here :(

What you could do is walk through the serde_json::Value and reconstruct a Jinja value without going via the serde system.

@janlugt
Copy link
Author

janlugt commented Nov 11, 2024

Thanks! If I serialize to a struct first, things work, since specific number types are known, so that's what I'll do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants