Kriskras99 commented on issue #449:
URL: https://github.com/apache/avro-rs/issues/449#issuecomment-3843389309
@PookieBuns sorry, I thought you meant the following didn't work:
```rust
#[test]
fn avro_rs_449_union_null_is_json_null() {
let v = Value::Union(0, Box::new(Value::Null));
let json: JsonValue = v.try_into().unwrap();
assert_eq!(json, JsonValue::Null); // This works
}
```
But the problem is this:
```rust
#[test]
fn avro_rs_449_union_int_is_json_int_value() {
let v = Value::Union(1, Box::new(Value::Int(42)));
let json: JsonValue = v.try_into().unwrap();
assert_eq!(json, json!({"int": 42})); // This panics
}
```
We can fix this for primitive types, but for named types we don't actually
have the name of the type in `Value`. So to have a spec implementation of JSON
serialisation we'll have to introduce a new function (something like
`Value::to_json(schema: &Schema) -> serde_json::Value`).
If you want to take a stab at implementing it, you're more than welcome! You
can assign me to review the PR.
--
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]