[ 
https://issues.apache.org/jira/browse/AVRO-1568?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14496556#comment-14496556
 ] 

Sachin Goyal commented on AVRO-1568:
------------------------------------

[~rdblue], can you provide an example for the below comment?
{quote}
 If it were, then you'd be able to set both the conversion from a third-party 
object and specifically set its schema. What I like about that way to handle 
this is that it uses the public API of the third party object, which would be 
less likely to have problems as that code changes. Using reflection to save the 
fields of a third-party object violates that object's guarantees by going 
directly to its private data, but relying on its API has some compatibility 
guarantees. Of course, the drawback is that you are responsible for maintaining 
the conversion.
{quote}

For the following:
{quote}
Why not get the class from of the Field and use that instead of tying 
serialization to both type and reference location?
{quote}
Consider a superclass which has several derived classes. If one were to support 
all the possible subclasses of such a class in one's code (those subclasses 
which are serialized too), he would need to create a gigantic UNION schema for 
every such field.
Where as with the field-level setSchema() method, one can limit the schema to 
only those types which are known.

This is especially useful when we are serializing a particular object and know 
exactly the type of a field. Makes the schema much less bulky.
We can think of field-level setSchema as a fine-tuned version of class-level 
setSchema.

> Allow Java polymorphism in Avro for third-party code
> ----------------------------------------------------
>
>                 Key: AVRO-1568
>                 URL: https://issues.apache.org/jira/browse/AVRO-1568
>             Project: Avro
>          Issue Type: Improvement
>    Affects Versions: 1.7.6
>            Reporter: Sachin Goyal
>
> A large number of Java designs interacting with databases with 
> Hibernate/Couchbase (perhaps, even otherwise) have Java polymorphism of the 
> form:
> {code:java}
> class Base 
> {
>    Integer a = 5;
> }
> class Derived extends Base
> {
>     String b = "Foo";
> }
> class PolymorphicDO
> {
>    Base b = new Derived();
> }
> {code}
> Jackson handles this kind of field by using annotations such as:
> {code}
> @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = 
> JsonTypeInfo.As.PROPERTY, property = "@class”)
> {code}
> If such a thing can be added to Avro, all those Java designs could become 
> immediately usable with Avro. They would also become Hadoop compatible due to 
> AvroSerde.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to