I'm writing a simple REST API using Iron. There is an endpoint that parses incoming JSON into a structure. Not all fields of the structure are mandatory, some can be omitted. I'm trying to parse JSON with the bodyparser crate like this
let body = r.get::<bodyparser::Struct<MyFancyDataRequest>>();
The structure looks like this:
#[derive(Serialize, Deserialize, Clone)]
struct MyFancyDataRequest {
name: String,
address: String
}
The incoming JSON contains only "name"
{"name":"John Doe"}
I'm getting the following error:
Can't parse body to the struct (missing field `address`)
Is it possible to make the parser ignore the missing fields? For instance, in Go I could mark optional struct fields with the omitempty
tag.