Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3901

[Rust] Better serde union support

    XMLWordPrintableJSON

Details

    Description

      (Full code examples in unit tests of attached PR).

      Want to be able to serde to/from an enum containing structs for a union schema containing record(s):

      {
        "name": "C",
        "type": "record",
        "fields": [
      ...
          {"name": "field_union", "type": ["A", "B"]},
      ...
        ]
      }
      

      With code like:

      struct A {...}
      struct B {...}
      
      #[serde(untagged)]
      enum UnionAB { A(A), B(B)}
      
      struct C {
        ...
        field_union: UnionAB,
        ...
      }
      

      Likewise, want to be able to serde where the schema includes null:

      {
        "name": "E",
        "type": "record",
        "fields": [
          ...
          {"name": "field_union", "type": ["A", "null", "B"]},
          ...
        ]
      }
      
      #[serde(untagged)]
      enum UnionANoneB {
          A(A),
          None,
          B(B),
      }
      

      Attachments

        Issue Links

          Activity

            People

              mgrigorov Martin Tzvetanov Grigorov
              chupaty Simon Gittins
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h