Skip to content

Commit

Permalink
AVRO-3886: [Rust] Use all kinds of JSON values for the attributes to …
Browse files Browse the repository at this point in the history
…serialize

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
  • Loading branch information
martin-g committed Oct 17, 2023
1 parent 487540c commit 2cbff43
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lang/rust/avro/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6138,18 +6138,29 @@ mod tests {

#[test]
fn avro_3886_serialize_attributes() -> TestResult {
let attributes = BTreeMap::from([
("string_key".into(), "value".into()),
("number_key".into(), 1.23.into()),
("null_key".into(), Value::Null),
(
"array_key".into(),
Value::Array(vec![1.into(), 2.into(), 3.into()]),
),
("object_key".into(), Value::Object(Map::default())),
]);

// Test serialize enum attributes
let schema = Schema::Enum(EnumSchema {
name: Name::new("a")?,
aliases: None,
doc: None,
symbols: vec![],
default: None,
attributes: BTreeMap::from([("logicalType".into(), "time-millis".into())]),
attributes: attributes.clone(),
});
let serialized = serde_json::to_string(&schema)?;
assert_eq!(
r#"{"type":"enum","name":"a","symbols":[],"logicalType":"time-millis"}"#,
r#"{"type":"enum","name":"a","symbols":[],"array_key":[1,2,3],"null_key":null,"number_key":1.23,"object_key":{},"string_key":"value"}"#,
&serialized
);

Expand All @@ -6159,11 +6170,11 @@ mod tests {
aliases: None,
doc: None,
size: 1,
attributes: BTreeMap::from([("logicalType".into(), "time-millis".into())]),
attributes: attributes.clone(),
});
let serialized = serde_json::to_string(&schema)?;
assert_eq!(
r#"{"type":"fixed","name":"a","size":1,"logicalType":"time-millis"}"#,
r#"{"type":"fixed","name":"a","size":1,"array_key":[1,2,3],"null_key":null,"number_key":1.23,"object_key":{},"string_key":"value"}"#,
&serialized
);

Expand All @@ -6174,11 +6185,11 @@ mod tests {
doc: None,
fields: vec![],
lookup: BTreeMap::new(),
attributes: BTreeMap::from([("logicalType".into(), "time-millis".into())]),
attributes,
});
let serialized = serde_json::to_string(&schema)?;
assert_eq!(
r#"{"type":"record","name":"a","fields":[],"logicalType":"time-millis"}"#,
r#"{"type":"record","name":"a","fields":[],"array_key":[1,2,3],"null_key":null,"number_key":1.23,"object_key":{},"string_key":"value"}"#,
&serialized
);

Expand Down

0 comments on commit 2cbff43

Please sign in to comment.