Comments (3)
As far as I can tell, this is a duplicate of #1051. That issue is about Box<RawValue>
and #[serde(flatten)]
not working together for deserialization when Box<RawValue>
appears somewhere inside the flattened data structure. Could you please explain what aspect of it is not duplicated?
from json.
In the example you gave,
#[derive(Deserialize, Debug)]
struct Repro {
id: String,
#[serde(flatten)]
value: Box<RawValue>,
}
I find it clear that the RawValue
can't work.
If there's an indirection (another struct) between #[serde(flatten)]
and the Box<RawValue>
though, it should be possible to make it work, e.g. in the example of #883, we have the following:
#![allow(dead_code)]
use serde::Deserialize;
use std::error::Error;
#[derive(Deserialize)]
struct Abc {
#[serde(flatten)]
pub def: Def,
}
#[derive(Deserialize)]
struct Def {
pub ghi: Box<serde_json::value::RawValue>,
}
fn main() -> Result<(), Box<dyn Error>> {
let _: Def = serde_json::from_str(r#"{"ghi": {}}"#).unwrap();
let _: Abc = serde_json::from_str(r#"{"ghi": {}}"#).unwrap();
Ok(())
}
As we can see, the "raw json string" of the "ghi"
key will always be contiguous, so it should™ be possible to create the RawValue
.
Upon re-reading #1051, I can now see how the issues are closer than I thought, so I see why it was marked as duplicate. I feel the reasoning given there doesn't apply here though. It makes sense that a raw value doesn't work if directly marked as #[serde(flatten)]
.
from json.
I think the indirection is incidental to the reason this isn't working, so they are duplicates. It is possible to do it differently but that is tracked by serde-rs/serde#1183.
from json.
Related Issues (20)
- impl IntoDeserializer for &RawValue? HOT 1
- Duplicated field in output
- Deserilazing `Cow<'_, serde_json::value::RawValue>` always allocates
- String keys with 0s at the front can not be converted to numbers
- Feature request: add Number::from_i64 and Number::from_u64
- Wrong positions for `InvalidUnicodeCodePoint` caused by `from_utf8`
- Cannot deserialize empty tuple variant HOT 1
- How about the Performance between `from_str` and `from_value`?
- Global configuration
- how to auto remove blank space?
- Improve DeserializeSeed documentation
- Deserializing lone surrogate to ByteBuf fails when it's nested in an enum HOT 1
- Is there a way to implement deserialize_in_place?
- Simplify array of objects to 2d array HOT 2
- Conditional Security Risk: `to_vec()` may retain sensitive data in memory on shared systems
- Is it possible to add context to the serializer object?
- Option<Option<T>> does not roundtrip correctly HOT 1
- tests don't compile on stable Rust: std::hash::RandomState only present on nightly
- Bug: untagged union fails to deserialize hashmap with usize as keys
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json.