-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
extra::json: Remove or rework ToJson #9028
Comments
I use to_json() a lot and find it quite handy when packaging up rust native data types for Json streaming. I think if extra::json::Encoder ( and PrettyEncoder ) could be limited to encoding Json values the problem would be solved. Other than that I find both the encoders pretty useful. Thanks. |
I think this may just point to a need for clarification in the docs. I'd expect ToJson to perform a conversion to json that creates a very specific representation of whatever type implements it. On the other hand, I expect Encoder to perform a conversion that creates a more general representation which is therefore available to more types. Unfortunately, the difference is not very clear in the docs, and ToJson and Encoder/Decoder were indeed very intertwined, and may still be. |
I think |
Triage bump. By checking the code, this is still the case. This issues seems legit to me. I don't think removing |
The JSON spec requires that these special values be serialized as "null"; the current serialization breaks any conformant JSON parser. So encoding needs to output "null", `to_json` on floating-point types can return `Null` as well as `Number` values, and reading a `Null` value when specifically expecting a number should be interpreted as NaN. There's no way to round-trip Infinity through JSON. This is my first attempt at both writing Rust and opening pull requests, so please dial your derp detector up to eleven when reviewing. A `rustc --test lib.rs` in `libserialize` passes all tests; a `make check` of the whole tree fails with the error below, but it doesn't look obviously related and the docs say that `make check` is known to be flaky on Windows. ---- [compile-fail] compile-fail/svh-change-significant-cfg.rs stdout ---- task '[compile-fail] compile-fail/svh-change-significant-cfg.rs' failed at 'called `Result:: unwrap()` on an `Err` value: couldn't create file (end of file (unknown error); path=i686-pc-mingw32 \test\compile-fail\svh-a-base.err; mode=truncate; access=write)', C:\msys\home\Mike\rust\src\libcore \result.rs:545 Incidentally, it may just be my lack of familiarity with the language and its idioms, but the duplication between `Encoder`/`PrettyEncoder` had a distinct code smell to it. The size of the file (~3500 lines) also made it a bit hard to navigate. Has there been any discussion of refactoring and/or breaking it up? I couldn't find anything in Issues except the ancient #9028.
Encoding has been moved out, and we've had some related improvements since then. I'm giving this a close. If you feel some of this is still important, please open it on https://github.com/rust-lang/rustc-serialize |
confirm using chain in collapsible_span_lint_calls close rust-lang#8798 This PR fixes false positive when using chain in `collapsible_span_lint_calls`. changelog: None
There are two ways to encode values into json in string form, and they can provide different results or be wrong:
serialize::Encoder
json::Encoder
implements theEncoder
trait, so you can give it arbitrary values, as long as they implementEncodable
, and it will output json, or json-like text.We need to provide a single method of encoding to Json, and make sure we use
serialize
correctly if we use it.The ToJson trait expresses the restriction that only maps with string keys can be encoded to Json. This is easy to step around by using the other json encoding method, which results in invalid json.
The text was updated successfully, but these errors were encountered: