You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by GitBox <gi...@apache.org> on 2020/04/23 01:37:42 UTC

[GitHub] [avro] anhldbk commented on a change in pull request #842: AVRO-2723: Refactor ReflectData to allow derived classes to customize default values for fields

anhldbk commented on a change in pull request #842:
URL: https://github.com/apache/avro/pull/842#discussion_r413445873



##########
File path: lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
##########
@@ -110,14 +112,96 @@ public static ReflectData get() {
   }
 
   /**
-   * Cause a class to be treated as though it had an {@link Stringable}
-   ** annotation.
+   * Cause a class to be treated as though it had an {@link Stringable} *
+   * annotation.
    */
   public ReflectData addStringable(Class c) {
     stringableClasses.add(c);
     return this;
   }
 
+  /**
+   * If this flag is set to true, default values for fields will be assigned
+   * dynamically using Java reflections. Let's call this feature `default
+   * reflection`. Initially this feature is disabled
+   */
+  private boolean defaultGenerated = false;
+
+  /**
+   * Enable or disable `default reflection`
+   *
+   * @param enabled set to `true` to enable the feature. This feature is disabled
+   *                by default
+   * @return The current instance
+   */
+  public ReflectData setDefaultsGenerated(boolean enabled) {
+    this.defaultGenerated = enabled;
+    return this;
+  }
+
+  private final Map<String, Object> defaultValues = new WeakHashMap<>();

Review comment:
       @cutting Agree. One small question: can I use `Map<Type, Object>` instead?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org