Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

QUESTION: decoded from blank dictionary field #399

Open
jjeffcaii opened this issue Dec 12, 2023 · 0 comments
Open

QUESTION: decoded from blank dictionary field #399

jjeffcaii opened this issue Dec 12, 2023 · 0 comments

Comments

@jjeffcaii
Copy link

I have an Endpoint struct following the codes below:

#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
pub struct ClientTLS {
    pub crt: Option<String>,
    pub key: Option<String>,
    pub sni: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Endpoint {
    pub address: String,
    pub tls: Option<ClientTLS>,
}

I'm trying to parse from a blank tls field:

       // equals the json: {"address": "127.0.0.1:80", "tls": {}}
        let input = r#"
        address: 127.0.0.1:80
        tls:
        "#;

        let endpoint: Endpoint = serde_yaml::from_str(input).unwrap();

        println!("endpoint: {:?}", endpoint);
        // will print: Endpoint { address: "127.0.0.1:80", tls: None }

My expected value is the tls field should be Some( ClientTLS: {crt: None, key: None, sni: None} ) like the behavior of serde_json, but it seems decoded as None.

How to fix my codes to return the expected value?

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant