[ 
https://issues.apache.org/jira/browse/AVRO-3484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17523536#comment-17523536
 ] 

Martin Tzvetanov Grigorov commented on AVRO-3484:
-------------------------------------------------

It seems we will need to use string as attribute value (syn/darling does not 
support anything else).

 
{code:java}
#[derive(Debug, Serialize, Deserialize, AvroSchema, Clone, PartialEq)] 
struct TestBasicWithDefaults {
    #[avro(default = "0")]
    int: u32,

    #[avro(default = "true")]
    condition: bool,

    #[avro(default = "\"abc\"")]
    str: String,

    #[avro(default = "{\"a\": 1, \"b\": 2}")]
    map: Map<String, i32>,

    #[avro(default = "[1, 2, 3]")] 
    array: Vec<i32>,

     #[avro(default = "FOO")] 
     myenum: MyEnum,
} {code}
 

And then set the value as-is in the generated schema.

 

Spec: https://avro.apache.org/docs/current/spec.html#schema_record

> Rust: Implement derive default via annotation
> ---------------------------------------------
>
>                 Key: AVRO-3484
>                 URL: https://issues.apache.org/jira/browse/AVRO-3484
>             Project: Apache Avro
>          Issue Type: Improvement
>            Reporter: Jack Klamer
>            Assignee: Jack Klamer
>            Priority: Major
>
> Origin Comment: https://github.com/apache/avro/pull/1631#discussion_r845826110
> Follow up on the avro derive work. Will want to be able to set the default 
> for a field inside a struct using annotations



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to