Hi,
I.m wondering if I'm missing an incantation for 'compile
schema/protocol' in Avro tools to handle defaults. Given this schema,
[[[
{
"name": "avro.Message",
"type": "record",
"fields": [
{
"name": "foo",
"type": "string",
"default":"quux"
},
{
"name": "bar",
"type": "string"
}
]
}
]]]
and running it through 'avro-tools-1.3.2.jar compile schema', I get this
object
[[[
package avro;
@SuppressWarnings("all")
public class Message extends org.apache.avro.specific.SpecificRecordBase
implements org.apache.avro.specific.SpecificRecord {
public static final org.apache.avro.Schema SCHEMA$ =
org.apache.avro.Schema.parse("{\"type\":\"record\",\"name\":\"Message\",\"namespace\":\"avro\",\"fields\":[{\"name\":\"foo\",\"type\":\"string\",\"default\":\"quux\"},{\"name\":\"bar\",\"type\":\"string\"}]}");
public org.apache.avro.util.Utf8 foo = new Utf8("quux");
public org.apache.avro.util.Utf8 bar;
public org.apache.avro.Schema getSchema() { return SCHEMA$; }
public java.lang.Object get(int field$) {
switch (field$) {
case 0: return foo;
case 1: return bar;
default: throw new org.apache.avro.AvroRuntimeException("Bad index");
}
}
@SuppressWarnings(value="unchecked")
public void put(int field$, java.lang.Object value$) {
switch (field$) {
case 0: foo = (org.apache.avro.util.Utf8)value$; break;
case 1: bar = (org.apache.avro.util.Utf8)value$; break;
default: throw new org.apache.avro.AvroRuntimeException("Bad index");
}
}
}
]]]
Should this line,
[[[
public org.apache.avro.util.Utf8 foo;
]]]
be,
[[[
public org.apache.avro.util.Utf8 foo
= new org.apache.avro.util.Utf8("quux");
]]]
?
Fwiw, changing the object's 'foo' field above to have the default stops
the IPC server from barfing with an NPE (@
org.apache.avro.io.BinaryEncoder.writeString(BinaryEncoder.java:133))
when a client creates a message object only sets 'bar', and then sends
the Message to the server via .
Bill