Skip to content

Multiple serialization/deserialization implementations for the same type.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

yogevm15/serde_many

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serde Many   Latest Version

Serde Many enables multiple serialization/deserialization implementations for the same type. The design ensures seamless integration with the serde crate.

Example

use serde_many::{DeserializeMany, SerializeMany};

/// Marker for the default serde implementation.
struct Default;

/// Marker for a special serde implementation.
struct Special;

#[derive(SerializeMany, DeserializeMany)]
#[serde_many(default = "Default", special = "Special")] // Declaring the implementation markers.
struct Point {
    #[serde(special(rename = "x_value"))]
    x: i32,
    #[serde(special(rename = "y_value"))]
    y: i32,
}

#[test]
fn it_works() {
    let mut serialized = Vec::new();
    let mut serializer = serde_json::Serializer::pretty(&mut serialized);
    let val = Point { x: 0, y: 0 };

    SerializeMany::<Default>::serialize(&val, &mut serializer).unwrap();
    assert_eq!(
        String::from_utf8_lossy(&serialized),
        "{
  \"x\": 0,
  \"y\": 0
}"
    );

    serialized.clear();
    let mut serializer = serde_json::Serializer::pretty(&mut serialized);
    SerializeMany::<Special>::serialize(&val, &mut serializer).unwrap();
    assert_eq!(
        String::from_utf8_lossy(&serialized),
        "{
  \"x_value\": 0,
  \"y_value\": 0
}"
    )
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Multiple serialization/deserialization implementations for the same type.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages