avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject [27/35] avro git commit: AVRO-1860: Java: Field#DefaultVal() returns Ints for Long fields. Contributed by Gabor Szadovszky.
Date Sat, 05 Nov 2016 20:20:44 GMT
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/f02db391
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/f02db391
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/f02db391

Branch: refs/heads/branch-1.8
Commit: f02db39114cd3b1bd02e87b86812f2c0cafdba86
Parents: aa0ee44
Author: Doug Cutting <cutting@apache.org>
Authored: Thu Oct 6 14:43:29 2016 -0700
Committer: Ryan Blue <blue@apache.org>
Committed: Sat Nov 5 13:18:48 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/f02db391/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 66e73ac..0457922 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -72,6 +72,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/f02db391/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/f02db391/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