[
https://issues.apache.org/jira/browse/AVRO-2723?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17032796#comment-17032796
]
Anh Le commented on AVRO-2723:
------------------------------
[~rskraba] I'm really glad to receive your thoughtful comments.
> However, I'm pretty sure you *can* apply it to *{{Integer}}* and complex
> classes.
Correct. I can use *{{Integer}}* but I can't use *String*.
The code below:
{code:java}
class User {
@AvroDefault("Andy")
public String first;
}
Schema schema = ReflectData.get().getSchema(User.class);
{code}
will trigger an exception:
{noformat}
Exception in thread "main" org.apache.avro.AvroRuntimeException:
java.lang.RuntimeException: com.fasterxml.jackson.core.JsonParseException:
Unrecognized token 'Andy': was expecting ('true', 'false' or 'null')
at [Source: (String)"Andy"; line: 1, column: 9]{noformat}
Anything wrong?
> I'd suggest picking something more explicit. *{{createSchemaDefaultValue()}}*
> perhaps?
Well pick. But if without refactoring ReflectData, where we will put this
function?
[~cutting] Do you think we need to refactor ReflectData? I really need it to
expose overridable functions for extracting default values through
instantiation.
> Avro Java: Obtaining default values for POJO objects with ReflectData
> ---------------------------------------------------------------------
>
> Key: AVRO-2723
> URL: https://issues.apache.org/jira/browse/AVRO-2723
> Project: Apache Avro
> Issue Type: Wish
> Components: java
> Affects Versions: 1.9.1
> Reporter: Anh Le
> Priority: Critical
>
> Hi guys,
>
> I've got a simple app using Avro Reflection:
>
> {code:java}
> public class App {
> public static void main(String[] args) {
> testReflection();
> }
> static class User {
> public String first = "Andy";
> public String last = "Le";
> }
> static void testReflection(){
> // get the reflected schema for packets
> Schema schema = ReflectData.AllowNull.get().getSchema(User.class);
> System.out.println(schema.toString(true));
> }
> {code}
> The output on console will be:
> {noformat}
> {
> "type" : "record",
> "name" : "User",
> "namespace" : "App",
> "fields" : [ {
> "name" : "first",
> "type" : [ "null", "string" ],
> "default" : null
> }, {
> "name" : "last",
> "type" : [ "null", "string" ],
> "default" : null
> } ]
> }
> {noformat}
>
> As you can see, there's no default values for fields. Would you please tell
> me how to obtain such values?
> Thank you.
>
>
>
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)