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

Schema.toString() strips out field docs

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.3.3
    • 1.4.0
    • java
    • None

    Description

      Although avro can successfully parse schema text that contains a "doc" on a Schema.Field, when a Schema containing a field doc is serialized (via Schema.toString()) the doc does not get written.

      The following JUnit test case demonstrates this problem:

      TestAvroFieldDocSerialization.java
      import junit.framework.TestCase;
      
      import org.apache.avro.Schema;
      
      public class TestAvroFieldDocSerialization extends TestCase {
      
      	public void testAvroFieldDocSerialization() {
      		String schemaStr =
      			"{"+
      			"	\"name\": \"Rec\","+
      			"	\"type\": \"record\","+
      			"	\"fields\" : ["+
      			"		{\"name\": \"f\", \"type\": \"int\", \"doc\": \"test\"}"+
      			"	]"+
      			"}";
      		Schema schema = Schema.parse(schemaStr);
      		verifyFieldDoc(schema);
      
      		schemaStr = schema.toString();
      		schema = Schema.parse(schemaStr);
      		verifyFieldDoc(schema);
      	}
      
      	private void verifyFieldDoc(Schema schema) {
      		Schema.Field field = schema.getField("f");
      		assertEquals("test", field.doc());
      	}
      }
      

      Note that the first call to verifyFieldDoc() succeeds, while the second one fails. They should both succeed (in my opinion).

      Attachments

        1. AVRO-612.patch
          2 kB
          Doug Cutting

        Activity

          People

            cutting Doug Cutting
            darose David Rosenstrauch
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: