Skip to content

Compilation error: the trait bound serde::Serializer is not satisfied for unions #923

@antkmsft

Description

@antkmsft

This affects specification/datafactory/resource-manager/Microsoft.DataFactory/DataFactory

The errors are

error[E0277]: the trait bound `&std::option::Option<Value>: serde::Serializer` is not satisfied
    --> spec\rmDataFactory\src\generated\models\unions_serde.rs:1483:17
     |
1476 |             } => UnknownDatasetStorageFormatType::serialize(
     |                  ------------------------------------------ required by a bound introduced by this call
...
1483 |                 serializer,
     |                 ^^^^^^^^^^ the trait `Serializer` is not implemented for `&std::option::Option<Value>`
     |
     = help: the following other types implement trait `Serializer`:
               &'a mut serde_json::ser::Serializer<W, F>
               &mut Formatter<'a>
               quick_xml::se::Serializer<'w, 'r, W>
               quick_xml::se::content::ContentSerializer<'w, 'i, W>
               quick_xml::se::element::ElementSerializer<'w, 'k, W>
               quick_xml::se::key::QNameSerializer<W>
               quick_xml::se::simple_type::AtomicSerializer<W>
               quick_xml::se::simple_type::SimpleTypeSerializer<W>
             and 2 others
note: required by a bound in `generated::models::models::_::_serde::Serialize::serialize`
    --> C:\Users\antk\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\serde_core-1.0.228\src\ser\mod.rs:267:12
     |
 265 |     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
     |        --------- required by a bound in this associated function
 266 |     where
 267 |         S: Serializer;
     |            ^^^^^^^^^^ required by this bound in `Serialize::serialize`

error[E0277]: the trait bound `&std::option::Option<Value>: serde::Serializer` is not satisfied
    --> spec\rmDataFactory\src\generated\models\unions_serde.rs:1476:18
     |
1476 |               } => UnknownDatasetStorageFormatType::serialize(
     |  __________________^
1477 | |                 &UnknownDatasetStorageFormatType {
1478 | |                     additional_properties,
1479 | |                     deserializer,
...    |
1483 | |                 serializer,
1484 | |             ),
     | |_____________^ the trait `Serializer` is not implemented for `&std::option::Option<Value>`
     |
     = help: the following other types implement trait `Serializer`:
               &'a mut serde_json::ser::Serializer<W, F>
               &mut Formatter<'a>
               quick_xml::se::Serializer<'w, 'r, W>
               quick_xml::se::content::ContentSerializer<'w, 'i, W>
               quick_xml::se::element::ElementSerializer<'w, 'k, W>
               quick_xml::se::key::QNameSerializer<W>
               quick_xml::se::simple_type::AtomicSerializer<W>
               quick_xml::se::simple_type::SimpleTypeSerializer<W>
             and 2 others

Generated code

// unions_serde.rs

impl Serialize for DatasetStorageFormat {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        match self {
            DatasetStorageFormat::AvroFormat(avro_format) => {
                AvroFormat::serialize(avro_format, serializer)
            }
            DatasetStorageFormat::JsonFormatNew(json_format_new) => {
                JsonFormatNew::serialize(json_format_new, serializer)
            }
            DatasetStorageFormat::OrcFormat(orc_format) => {
                OrcFormat::serialize(orc_format, serializer)
            }
            DatasetStorageFormat::ParquetFormat(parquet_format) => {
                ParquetFormat::serialize(parquet_format, serializer)
            }
            DatasetStorageFormat::TextFormat(text_format) => {
                TextFormat::serialize(text_format, serializer)
            }
            DatasetStorageFormat::UnknownType {
                additional_properties,
                deserializer,
                serializer,
                type_prop,
            } => UnknownDatasetStorageFormatType::serialize(
                &UnknownDatasetStorageFormatType {
                    additional_properties,
                    deserializer,
                    serializer,
                    type_prop,
                },
                serializer,
            ),
        }
    }
}

and

// unions.rs

#[doc = r#"The format definition of a storage."#]
#[derive(Clone, Deserialize, SafeDebug)]
#[serde(tag = "type")]
pub enum DatasetStorageFormat {
    AvroFormat(AvroFormat),

    #[serde(rename = "JsonFormat")]
    JsonFormatNew(JsonFormatNew),

    OrcFormat(OrcFormat),

    ParquetFormat(ParquetFormat),

    TextFormat(TextFormat),

    #[serde(untagged)]
    UnknownType {
        /// Contains unnamed additional properties.
        additional_properties: Option<HashMap<String, Value>>,

        /// Deserializer. Type: string (or Expression with resultType string).
        deserializer: Option<Value>,

        /// Serializer. Type: string (or Expression with resultType string).
        serializer: Option<Value>,

        /// Type of dataset storage format.
        type_prop: Option<String>,
    },
}

tsp:

/**
 * The format definition of a storage.
 */
@discriminator("type")
model DatasetStorageFormat {
  ...Record<unknown>;

  /**
   * Type of dataset storage format.
   */
  #suppress "@azure-tools/typespec-azure-core/no-string-discriminator" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
  type: string;

  /**
   * Serializer. Type: string (or Expression with resultType string).
   */
  serializer?: Dfe<string>;

  /**
   * Deserializer. Type: string (or Expression with resultType string).
   */
  deserializer?: Dfe<string>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Untriaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions