You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by S G <sg...@gmail.com> on 2014/08/22 20:45:49 UTC

How to handle entities with type-parameters

Hi,

Does anyone know how I can avoid an exception for the following code:

-------------------------------------------------------------------
public class EntityWrapper<T>
{
    T obj;
}

public class Entity
{
    Integer a = 1;
    String b = "Foo";
}

EntityWrapper<Entity> en = new EntityWrapper<Entity>();
en.obj = new Entity();
ReflectData.getSchema(en.getClass());
-------------------------------------------------------------------


And the exception is:


org.apache.avro.AvroTypeException: Unknown type: T

at org.apache.avro.specific.SpecificData.createSchema(SpecificData.java:260)

at org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:542)

at
org.apache.avro.reflect.ReflectData.createFieldSchema(ReflectData.java:645)

at
org.apache.avro.reflect.ReflectData$AllowNull.createFieldSchema(ReflectData.java:78)

at org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:500)

at org.apache.avro.specific.SpecificData.getSchema(SpecificData.java:194)



Thx - Sachin

Re: How to handle entities with type-parameters

Posted by Sachin Goyal <sg...@walmartlabs.com>.
Hi,

I have created https://issues.apache.org/jira/browse/AVRO-1571 to track this.
It shows a little bit more complex version of the problem and a possible solution.

Thanks - Sachin

From: S G <sg...@gmail.com>>
Reply-To: "user@avro.apache.org<ma...@avro.apache.org>" <us...@avro.apache.org>>
Date: Friday, August 22, 2014 at 11:45 AM
To: "user@avro.apache.org<ma...@avro.apache.org>" <us...@avro.apache.org>>
Subject: How to handle entities with type-parameters


Hi,

Does anyone know how I can avoid an exception for the following code:

-------------------------------------------------------------------
public class EntityWrapper<T>
{
    T obj;
}

public class Entity
{
    Integer a = 1;
    String b = "Foo";
}

EntityWrapper<Entity> en = new EntityWrapper<Entity>();
en.obj = new Entity();
ReflectData.getSchema(en.getClass());
-------------------------------------------------------------------



And the exception is:


org.apache.avro.AvroTypeException: Unknown type: T

at org.apache.avro.specific.SpecificData.createSchema(SpecificData.java:260)

at org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:542)

at org.apache.avro.reflect.ReflectData.createFieldSchema(ReflectData.java:645)

at org.apache.avro.reflect.ReflectData$AllowNull.createFieldSchema(ReflectData.java:78)

at org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:500)

at org.apache.avro.specific.SpecificData.getSchema(SpecificData.java:194)



Thx - Sachin