-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
#[serde(flatten)]
doesn't work with context!
(sometimes)
#222
Comments
I'm not entirely sure why flatten does not work here but given how big of a hack it is, I'm not terribly surprised. For what it's worth the issue here is unlikely to be #[derive(Serialize)]
struct Foo {
val2: i32,
#[serde(flatten)]
flattened: minijinja::Value,
} |
So the issue here is more or less the following: a \x01__minijinja_ValueHandle {
handle: i64
} The #[derive(Serialize)]
struct Foo {
val2: i32,
#[serde(flatten)]
flattened: minijinja::Value,
} Turns into this:
I changed the serialization format to an enum for testing purposes, but then the end result looks like this:
In some sense it would be necessary to detect that flattening is requested, and to then dump out the structural form of the value rather than the reference. There is currently no way to detect this as serde does not communicate to the serialization interface that flattening is requested. This relates to this issue in some sense: serde-rs/serde#1183 |
My hack from #223 failed with the latest serde release (serde-rs/serde#2786). I'm going to change it to use a tuple struct internally now instead of a tuple variant. This results in serde's flattener to issue a |
Description
minijinja::context!
and#[serde(flatten)]
sometimes don't work correctly together.Reproduction steps
cargo run
and observe the outputAdditional helpful information:
What did you expect
I was expecting
minijinja::context!
to be equal toserde_json::json!
The text was updated successfully, but these errors were encountered: