avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r986957 - in /avro/trunk: CHANGES.txt lang/java/src/java/org/apache/avro/Schema.java lang/java/src/test/java/org/apache/avro/TestSchema.java
Date Wed, 18 Aug 2010 21:35:15 GMT
Author: cutting
Date: Wed Aug 18 21:35:15 2010
New Revision: 986957

URL: http://svn.apache.org/viewvc?rev=986957&view=rev
Log:
AVRO-612. Java: Preserve field documentation when writing schemas.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/src/java/org/apache/avro/Schema.java
    avro/trunk/lang/java/src/test/java/org/apache/avro/TestSchema.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=986957&r1=986956&r2=986957&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Aug 18 21:35:15 2010
@@ -148,6 +148,8 @@ Avro 1.4.0 (unreleased)
 
     AVRO-609. Java: Fix JsonToBinaryFragmentTool to flush output. (cutting)
 
+    AVRO-612. Java: Preserve field documentation when writing schemas. (cutting)
+
 Avro 1.3.3 (7 June 2010)
 
   IMPROVEMENTS

Modified: avro/trunk/lang/java/src/java/org/apache/avro/Schema.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/Schema.java?rev=986957&r1=986956&r2=986957&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/Schema.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/Schema.java Wed Aug 18 21:35:15 2010
@@ -617,6 +617,8 @@ public abstract class Schema {
         gen.writeStringField("name", f.name());
         gen.writeFieldName("type");
         f.schema().toJson(names, gen);
+        if (f.doc() != null)
+          gen.writeStringField("doc", f.doc());
         if (f.defaultValue() != null) {
           gen.writeFieldName("default");
           gen.writeTree(f.defaultValue());

Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/TestSchema.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/TestSchema.java?rev=986957&r1=986956&r2=986957&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/TestSchema.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/TestSchema.java Wed Aug 18 21:35:15
2010
@@ -373,6 +373,20 @@ public class TestSchema {
   }
 
   @Test
+  public void testFieldDocs() {
+    String schemaStr = "{\"name\": \"Rec\",\"type\": \"record\",\"fields\" : ["+
+      "{\"name\": \"f\", \"type\": \"int\", \"doc\": \"test\"}]}";
+
+    // check field doc is parsed correctly
+    Schema schema = Schema.parse(schemaStr);
+    assertEquals("test", schema.getField("f").doc());
+    
+    // check print/read cycle preserves field doc
+    schema = Schema.parse(schema.toString());
+    assertEquals("test", schema.getField("f").doc());
+  }
+
+  @Test
   public void testAliases() throws Exception {
     String t1 = "{\"type\":\"record\",\"name\":\"a.b\","
       +"\"fields\":[{\"name\":\"f\",\"type\":\"long\"}]}";



Mime
View raw message