cargo serde_json 1.0.0

latest releases: 1.0.117, 1.0.116, 1.0.115...
7 years ago

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 return io::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.

Don't miss a new serde_json release

NewReleases is sending notifications on new releases.