Releases: serde-rs/json
v1.0.8
- Significant improvements to compile time of
derive(Deserialize)
generated code using JSON; see Improve compile time and executable size by counting lines of LLVM IR - Fix typo in error message when deserializing something that is not a boolean and the input contains
false
(#392, thanks @bouk)
Compatibility notes
Part of the improvement to compile time comes from having generic methods in serde_json instantiate many fewer Visitor trait methods than they used to. For example if a Deserialize impl is being deserialized from JSON and the impl indicates to Serde that the type u64 is expected, serde_json can avoid instantiating all of the Visitor methods that deal with string, borrowed string, unit, sequence, map, boolean, char, bytes, borrowed bytes, option, newtype, and enum. Previously all of these methods were instantiated and compile times were predictably poor in consequence. As of this release, serde_json instantiates only the expected Visitor methods and instead renders invalid_type error messages in a central place in the Deserializer that can be instantiated just once. This does not apply to deserialize_any for which it continues to be necessary to instantiate every Visitor method.
This does mean that code relying on the deserialize hint to be wrong may no longer deserialize successfully.
impl<'de> Deserialize<'de> for MyType {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>
{
struct MyVisitor;
impl<'de> Visitor<'de> for MyVisitor {
type Value = MyType;
fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("a string, although we ask the deserializer for u64")
}
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where E: de::Error
{
Ok(/* ... */)
}
}
// It used to be that serde_json would ignore this hint and call visit_str
// for string input, but in the general case that destroys compile times
// by instantiating far more Visitor methods than are ever used.
deserializer.deserialize_u64(MyVisitor)
}
}
v1.0.7
v1.0.6
v1.0.5
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v1.0.0
First of all, go read the Serde 1.0.0 release notes!
Zero-copy deserialization
This release supports Serde 1.0's zero-copy deserialization feature. This allows borrowed data to be deserialized efficiently and safely.
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
#[derive(Deserialize, Debug)]
struct User<'a> {
fingerprint: &'a str,
location: &'a str,
}
fn main() {
let j = "{
\"fingerprint\": \"0xF9BA143B95FF6D82\",
\"location\": \"Menlo Park, CA\"
}";
let u: User = serde_json::from_str(j).unwrap();
println!("{:#?}", u);
}
Breaking changes
-
The
StreamDeserializer
now only supports arrays and objects.Previously it supported any JSON value, leading to confusing behavior like
truetrue
being deserialized successfully as two boolean values. -
The
ToJson
trait has been removed.Please use
serde_json::to_value
instead. See #294 for some justification. -
Support for deserializing from Iterator<Item = io::Result<u8>> removed.
Please use
serde_json::from_reader
instead. -
The
Formatter
trait methods now returnio::Result
.Previously they returned
serde_json::Result
. There should be no reason for a formatter to fail other than IO. -
The
Formatter::write_string_fragment
method now receives&str
.Previously the method received
&[u8]
but it was always valid UTF-8. -
Conversion
From<io::Error> for serde_json::Error
removed.The
serde_json::Error
type is intended to be constructed by serde_json, not by your code. -
The writer argument is passed by value to
serde_json::to_writer
.The standard library provides
impl<'a, W: Write + ?Sized> Write for &'a mut W
so passing a&mut W
will continue to work.