|
|
-
Re: runtime error when casting Array<String> to String[]Doug Cutting 2012-07-02, 19:20
On Thu, Jun 28, 2012 at 7:02 PM, Sameer Deokule <[EMAIL PROTECTED]> wrote:
> Is mapping of avro arrays to java arrays instead of lists, still being > planned? This is possible in Avro 1.7 if you use ReflectDatumReader and the array schema includes either "java-class" or a "java-element-class" attribute. The "java-class" attribute should be an array class name e.g., "[I" for an int[] and "[Ljava.lang.String" for String[] -- see http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getName(). For example, an array of Strings might be represented either with the schema: {"type":"array", "items":"string", "java-class":"[Ljava.lang.String"} or with: {"type":"array", "items":"string", "java-element-class":"java.lang.String"} Note that ReflectDatumReader is a superclass of SpecificDatumReader and GenericDatumReader, so in addition to reading reflected records, it can also correctly read records defined by the specific compiler or if no class exists for a record it will use the generic representation. Doug |