[ 
https://issues.apache.org/jira/browse/AVRO-3177?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Theodore updated AVRO-3177:
---------------------------
    Description: 
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}
 But `from_value` fails with an error message `"unsupported union"`.

  was:
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}
 


> 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
>            Priority: Major
>
> 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}
>  But `from_value` fails with an error message `"unsupported union"`.



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

Reply via email to