[ 
https://issues.apache.org/jira/browse/AVRO-3232?focusedWorklogId=665668&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-665668
 ]

ASF GitHub Bot logged work on AVRO-3232:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/Oct/21 12:56
            Start Date: 14/Oct/21 12:56
    Worklog Time Spent: 10m 
      Work Description: martin-g edited a comment on pull request #1368:
URL: https://github.com/apache/avro/pull/1368#issuecomment-943329047


   Here is a test case that properly constructs a POJO:
   
   ```rust
   #[test]
       fn test_from_value_with_union() -> TestResult<()> {
           #[derive(Debug, Deserialize, PartialEq)]
           struct StructWithMapInner {
               map: Option<HashMap<String, i64>>,
           }
           #[derive(Debug, Deserialize, PartialEq)]
           struct StructWithMap {
               inner: StructWithMapInner,
           }
           let raw_map: HashMap<String, i64> = [
               ("one".to_string(), 1i64),
               ("three".to_string(), 3i64),
               ("two".to_string(), 2i64)
           ].iter().cloned().collect();
   
           let map = raw_map.iter()
               .map(|(k, v)| (k.clone(), Value::Long(*v)))
               .collect();
   
           let value = Value::Record(vec![(
               "inner".to_owned(),
               Value::Record(vec![
                   ("map".to_string(), Value::Union(Box::new(Value::Map(map)))),
                   // ("map".to_string(), Value::Map(map)),
               ]),
           )]);
   
           let result: StructWithMap = crate::from_value(&value)?;
           assert_eq!(result, StructWithMap{ inner: StructWithMapInner{ map: 
Some(raw_map) }});
           Ok(())
       }
   ```
   
   The key is that you need to use an `Option` for the `Union`.
   
   Everything works without your changes. 
   Just put this test at the bottom of `de.rs` and run `cargo test 
test_from_value_with_union`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 665668)
    Time Spent: 2h  (was: 1h 50m)

> Rust deserializer: add missing matches to deserialize_any union and string/map
> ------------------------------------------------------------------------------
>
>                 Key: AVRO-3232
>                 URL: https://issues.apache.org/jira/browse/AVRO-3232
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: rust
>            Reporter: Ultrabug
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 2h
>  Remaining Estimate: 0h
>
> When deserializing complex Avro schemas using from_value::<T> to map the data 
> to a struct, we get errors even if the Record itself has been deserialized 
> successfully.
> These errors come from the fact that `deserialize_any` from de.rs is missing 
> some matches.



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

Reply via email to