Serde - JSON deserialization

I have a Json:


I would like deserialize field def as String, because the def field is replaceable (generic).
How to do it?

Rust Playground

Take a look at the deserialize_with field attribute.

You can use RawValue to accept JSON on a field.

1 Like

I have a problem.

error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'de` due to conflicting requirements
 --> src/
9 |     def: &'a RawValue,
  |     ^^^

I'm solved this problem.

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Variable<'a>  {
    pub id: u32,
    pub name: String,
    def: &'a RawValue,
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Config<'a> {
     variables: Vec<Variable<'a>>,

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.