You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2025/08/12 06:50:10 UTC
(avro-rs) 01/01: Issue #252: Add an `Option` field with a `#[avro(default = "null")]`
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch avro-rs-252-derive-option-with-default
in repository https://gitbox.apache.org/repos/asf/avro-rs.git
commit 86ad0d004c708a8c2775fee8a0344d9d74cded19
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Tue Aug 12 09:49:04 2025 +0300
Issue #252: Add an `Option<String>` field with a `#[avro(default = "null")]`
https://github.com/apache/avro-rs/issues/252#issuecomment-3177888121
Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
---
avro_derive/tests/derive.rs | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/avro_derive/tests/derive.rs b/avro_derive/tests/derive.rs
index 82c377b..fe3c76d 100644
--- a/avro_derive/tests/derive.rs
+++ b/avro_derive/tests/derive.rs
@@ -1389,6 +1389,9 @@ mod test_derive {
#[avro(default = r#""Foo""#)]
myenum: MyEnum,
+
+ #[avro(default = r#"null"#)]
+ optional: Option<String>,
}
let schema = r#"
@@ -1442,6 +1445,11 @@ mod test_derive {
"symbols":["Foo", "Bar", "Baz"]
},
"default":"Foo"
+ },
+ {
+ "name":"optional",
+ "type": ["null", "string"],
+ "default":"null"
}
]
}
@@ -1471,6 +1479,7 @@ mod test_derive {
),
"c" => assert_eq!(None, field.default),
"myenum" => assert_eq!(Some(json!("Foo")), field.default),
+ "optional" => assert_eq!(Some(json!(null)), field.default),
_ => panic!("Unexpected field name"),
}
}
@@ -1490,6 +1499,7 @@ mod test_derive {
.collect(),
array: vec![4, 5, 6],
myenum: MyEnum::Bar,
+ optional: None,
});
}