Attribute Macro proto_json

Source
#[proto_json]
Expand description

Helps to glue together json and protobufs when placed on a valid prost::Message, prost::Enumeration, or prost::Oneof For structs, it walks the fields checking whether they are enums then adds serialize_with and deserialize_with attributes to relevant fields. Structs need to have the prost::Message attribute while Enums require the prost::Enumeration attribute For enums, it checks that the provided string is a valid variant then deserializes it as i32 to match the protobuf definitions

ยงExample

pub struct Address {
    country : String,
    city : String,
    state : Option<String>,
    street : String,
    line1   : String,
    line2   : Option<String>

Example with enums

pub enum Currency {
        USD = 0;
        GPB = 1;
        JPY = 2;