How should I specify fields that do not need to be serialized

use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct User {
    pub id: String,
    pub username: String,
    pub password: String,
    pub name: String,
    pub sex: u8,
    pub brithday: String,
    pub status: u8,
}

#[allow(dead_code)]
impl User {
    pub fn new(id: String, username: String, password: String, name: String, sex: u8, brithday: String, status: u8) -> User {
        User {
            id,
            username,
            password,
            name,
            sex,
            brithday,
            status,
        }
    }
}

When my interface requests, the following is the error message

Json deserialize error: missing field `id` at line 4 column 1

Can I add attributes to fields? If so, which attribute is it?

#[?????]
pub id: String,

https://serde.rs/attr-skip-serializing.html

thanks

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.