Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-2723

Avro Java: Obtaining default field values for POJO objects with ReflectData

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.9.1
    • 1.10.0
    • java
    • None

    Description

      Hi guys,

       

      I've got a simple app using Avro Reflection:

       

      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));
        }
      
      

      The output on console will be:

      {
        "type" : "record",
        "name" : "User",
        "namespace" : "App",
        "fields" : [ {
          "name" : "first",
          "type" : [ "null", "string" ],
          "default" : null
        }, {
          "name" : "last",
          "type" : [ "null", "string" ],
          "default" : null
        } ]
      }
      

       

      As you can see, there's no default values for fields. Would you please tell me how to obtain such values?

      Thank you.

       

       

       

       

       

      Attachments

        Issue Links

          Activity

            People

              anhldbk Andy Le
              anhldbk Andy Le
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: