Comments (11)
Im just leaving this as a note here:
A exposed (De)Serializer type is also required to drive something like serde_transcode (as seen here)
from serde-yaml.
I've just discovered Serde a few days ago and have since been trying to use it in a toy project/game, so please excuse the newbie question, but is a fix for this required for stateful deserialization with serde-yaml?
I'd need to deserialize names of items into items (e.g. Arc<Sprite>) by looking them up in a library of items (that I'd like to pass as state). It's not often that I don't have to look up anything at all during deserialization, so I'm hopeful that I'm missing something.
from serde-yaml.
From what I understand,
this is also a requirements to user serde_transcode with yaml too.
The documentation is casting json to json.
I'd like to cast yaml to json, and I suppose it is not possible right now.
from serde-yaml.
Workarounds: (v0.7.4)
For now one can deserialize from a Value, but if you do this the naive way you end up with terrible error messages for anything other than syntax errors. (e.g. Message("invalid value: map, expected map with a single key", None)
)
However, there is a workaround for that, too, for those who can afford it:
use ::serde_yaml::Value;
use ::std::io::Read;
use ::serde::de::DeserializeOwned;
fn read_yaml<T: DeserializeOwned>(mut r: impl Read) -> Result<T, Error> {
// First, read into a form that we can read from multiple times.
let mut s = String::new();
r.read_to_string(&mut s)?;
// Get a Value, which implements Deserializer.
let value = ::serde_yaml::from_str(&s)?;
match _read_using_serde_ignored(value) {
Ok(out) => Ok(out),
Err(_) => {
// That error message was garbage. Let's parse without serde_ignored
// directly from the string, to get an error message with position info.
::serde_yaml::from_str(&s)?;
unreachable!();
}
}
}
fn _read_using_serde_ignored<T: DeserializeOwned>(value: Value) -> Result<T, Error> {
::serde_ignored::deserialize(
value,
|path| warn!("Unused config item (possible typo?): {}", path),
).map_err(Into::into)
}
from serde-yaml.
I'd like to cast yaml to json, and I suppose it is not possible right now.
@mardiros: This is not true:
let v: serde_json::Value = serde_yaml::from_str(yml_string)?
from serde-yaml.
Thanks I didn't know that works!
https://github.com/mardiros/rustaman/blob/features/multi-requests/src/helpers/http.rs#L68
from serde-yaml.
@dtolnay I would like to work on this, I need it for babelfish as well, I just realized that I wanted to convert between json and yaml.
from serde-yaml.
Sounds good @pickfire, go for it.
from serde-yaml.
@dtolnay I think I might need some guidance on how to get this done. I thought it is just as easy as slapping pub against Deserializer
and Serializer
.
I noticed that there are src/read.rs
for both json and cbor, do I need to have that as well? Do I need to change the signature to something like impl <'de, R> Deserializer<R>
?
from serde-yaml.
I am not sure how this could be implemented using yaml-rust after trying out an implementation on #129.
Should we write ourselves?
from serde-yaml.
I believe this would be easier to implement after solving dtolnay/request-for-implementation#9 and switching backends.
from serde-yaml.
Related Issues (20)
- Feature Request: `yaml!()` macro similar to `serde_json::json!({})` HOT 2
- externally tagged enums not correctly parsed in 0.9.25 HOT 5
- "did not find expected node content" parse regression since 0.8
- #[serde(flatten)] disables treating an integer as a string
- Make Iterator implementation of Deserializer::from_reader lazy
- Fail to deserialize i128 in internally tagged enum HOT 1
- Deserialization using serde_yaml seems to be failing when it involves a nested struct
- [BUG] Tagged null at end of flow sequence gives scanner error
- Inconsistent Quoting Behavior in String Serialization HOT 2
- QUESTION: decoded from blank dictionary field
- Document the YAML specification version and schema
- Enhancement: Allow compact one-line representation of some fields HOT 1
- Yaml with colon at the beginning of a value won't parse
- Support for serialization/deserialization of nested enums HOT 1
- Deserializer only acknowledges first line of YAML HOT 2
- Long Map keys bug HOT 3
- Untagged variant will make tagged ones unparsable HOT 1
- Thoughts about libyaml-safer HOT 3
- how can I merge 2 serde_yaml::Value? HOT 1
- ignore trailing document separators
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 serde-yaml.