lite-json icon indicating copy to clipboard operation
lite-json copied to clipboard

derive Serialize Deserialize macros

Open xlc opened this issue 6 years ago • 4 comments

Add derive macro to for auto serialization and deserialization implementation generation.

xlc avatar Nov 26 '19 20:11 xlc

@xlc I want to try to tackle this issue.

Currently, I am using code here to get a certain value/object out from JsonValue. But this is kind of tedious. Will be nice if we can do something like what serde does.

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let point = Point { x: 1, y: 2 };

    let serialized = serde_json::to_string(&point).unwrap();
    println!("serialized = {}", serialized);

    let deserialized: Point = serde_json::from_str(&serialized).unwrap();
    println!("deserialized = {:?}", deserialized);

     // So in lite-json
    let deserialized2: Point = lite_json::parse_json(&serialized).unwrap().deserialize().unwrap();
}

I am still not sure about the implementation yet. How hard would it be to do something like this in no_std env?

jimmychu0807 avatar Apr 17 '20 09:04 jimmychu0807

@jimmychu0807 I have started it at #13 and you are welcome to finish it. You can PR into derive branch.

Current status is it compiles, but I never ran it once so likely missing a lot of details.

The code is heavily inspired by parity-scale-codec.

xlc avatar Apr 18 '20 06:04 xlc

Thanks. Let me take a look

jimmychu0807 avatar Apr 20 '20 04:04 jimmychu0807

I would love to see this 🤞

justinfrevert avatar Mar 13 '23 18:03 justinfrevert