You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Theodore (Jira)" <ji...@apache.org> on 2021/07/13 19:41:00 UTC

[jira] [Created] (AVRO-3177) Deserializing a HashMap with different possible value types

Theodore created AVRO-3177:
------------------------------

             Summary: Deserializing a HashMap with different possible value types
                 Key: AVRO-3177
                 URL: https://issues.apache.org/jira/browse/AVRO-3177
             Project: Apache Avro
          Issue Type: Wish
          Components: rust
            Reporter: Theodore


Hi!

I'm trying to convert a record that conforms to this schema:
{code:java}
const SCHEMA: &str = r#"
 {
 "type" : "record",
 "name" : "TestName123",
 "namespace" : "Microsoft.ServiceBus.Messaging",
 "fields" : [ {
 "name": "test_field_name",
 "type" : { "type": "map", "values": [ "long", "double", "string", "bytes" ] }
 }]
 }
 "#; {code}
to a Rust type defined like this:
{code:java}
pub struct TestName123 {
  pub test_field_name: HashMap<String, ???>
}
{code}
 using this code:
{code:java}
// `record` is an Avro `Value` type, specifically a `Value::Record`.
avro_rs::from_value::<TestName123>(record)
{code}
I can't seem to figure out the type for `test_field_name` map values. I just wanted to confirm that doing this is at least possible, and if it is if anyone would have any general pointers on the type.

I can't find any similar examples in the documentation. I have tried things like this:

 
{code:java}
#[derive(Clone, Debug, Deserialize)]
pub enum MapValue {
  MapValueLong(u64),
  MapValueDouble(f64),
  MapValueString(String),
  MapValueBytes(Bytes)
}
{code}
 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)