Serde: how to skip an array element?

Given the JSON array looks like this:

[
String,
String
u64,
String
]

I convert it to a Struct

#[derive(serde::Deserialize, Debug)]
        pub struct X{

    a: String,
    b: String,
    c: u64,
     #[serde(skip)]
    _ignore: String
        }

tried using #[serde(skip)]
but I get a trailing characters error.

I think you can use serde::de::IgnoredAny for this.

#[derive(serde::Deserialize, Debug)]
pub struct X {
    a: String,
    b: String,
    c: u64,
    _ignore: serde::de::IgnoredAny,
}

(serde(skip) doesn't do what you want because it means the field isn't part of the expected data to be deserialized; it's the opposite kind of absence.)

7 Likes

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.