avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject avro git commit: AVRO-1860: Java: Field#DefaultVal() returns Ints for Long fields. Contributed by Gabor Szadovszky.
Date Thu, 06 Oct 2016 21:49:05 GMT
Repository: avro
Updated Branches:
  refs/heads/master e276aa5e4 -> ef0e1a1a0


AVRO-1860: Java: Field#DefaultVal() returns Ints for Long fields.  Contributed by Gabor Szadovszky.


Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/ef0e1a1a
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/ef0e1a1a
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/ef0e1a1a

Branch: refs/heads/master
Commit: ef0e1a1a011298ee77f1112ec9709ef03c5035ab
Parents: e276aa5
Author: Doug Cutting <cutting@apache.org>
Authored: Thu Oct 6 14:43:29 2016 -0700
Committer: Doug Cutting <cutting@apache.org>
Committed: Thu Oct 6 14:43:29 2016 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |  3 +++
 .../src/main/java/org/apache/avro/Schema.java   |  2 +-
 .../java/org/apache/avro/TestSchemaBuilder.java | 20 ++++++++++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/avro/blob/ef0e1a1a/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index f205783..4a48a58 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -75,6 +75,9 @@ Trunk (not yet released)
 
     AVRO-1923: Stop infinite recursion in GenericData.toString. (Niels Basjes)
 
+    AVRO-1860: Java: Field#DefaultVal() returns Ints for Long fields.
+    (Gabor Szadovszky via cutting)
+
 Avro 1.8.1 (14 May 2016)
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/avro/blob/ef0e1a1a/lang/java/avro/src/main/java/org/apache/avro/Schema.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/Schema.java b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
index 8125692..2019c1f 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/Schema.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
@@ -435,7 +435,7 @@ public abstract class Schema extends JsonProperties {
      * @return the default value for this field specified using the mapping
      *  in {@link JsonProperties}
      */
-    public Object defaultVal() { return JacksonUtils.toObject(defaultValue); }
+    public Object defaultVal() { return JacksonUtils.toObject(defaultValue, schema); }
     public Order order() { return order; }
     @Deprecated public Map<String,String> props() { return getProps(); }
     public void addAlias(String alias) {

http://git-wip-us.apache.org/repos/asf/avro/blob/ef0e1a1a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaBuilder.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaBuilder.java b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaBuilder.java
index 70dc1e5..74d3022 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/TestSchemaBuilder.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/TestSchemaBuilder.java
@@ -725,4 +725,24 @@ public class TestSchemaBuilder {
     Assert.assertEquals(5, rec2read.get("newNullableIntWithDefault"));
   }
 
+  @Test
+  public void testDefaultTypes() {
+    Integer intDef = 1;
+    Long longDef = 2L;
+    Float floatDef = 3F;
+    Double doubleDef = 4D;
+    Schema schema = SchemaBuilder.record("r").fields()
+        .name("int").type().intType().intDefault(intDef)
+        .name("long").type().longType().longDefault(longDef)
+        .name("float").type().floatType().floatDefault(floatDef)
+        .name("double").type().doubleType().doubleDefault(doubleDef)
+        .endRecord();
+
+    Assert.assertEquals("int field default type or value mismatch", intDef, schema.getField("int").defaultVal());
+    Assert.assertEquals("long field default type or value mismatch", longDef, schema.getField("long").defaultVal());
+    Assert.assertEquals("float field default type or value mismatch", floatDef, schema.getField("float").defaultVal());
+    Assert.assertEquals("double field default type or value mismatch", doubleDef,
+        schema.getField("double").defaultVal());
+  }
+
 }


Mime
View raw message