You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Joel VanderWerf <jo...@gmail.com> on 2012/06/06 02:01:24 UTC

Re: using custom builders

On 05/17/2012 11:54 AM, Joel VanderWerf wrote:
>
> I'd like to subclass the avro-generated classes.
>
> Is it possible to tell avro to deserialize using a custom builder that
> instantiates my subclasses?
>
> There are some hints in the source code that this might be possible, but
> what I'd really like is a small, working example...

This may be what I'm looking for:

org.apache.avro.specific.SpecificData

The getClass() method perhaps can be overridden to map incoming record 
class names to java classes. Not sure if this is the right way to do it 
though. There's also a getClassName() which might be a better method to 
override.

Any thoughts?

What we are trying to do is emulate JAXB's ObjectFactory 
functionality[1], which lets you specify which subclasses of the 
generated classes are used for deserialization.

-----
[1] http://jaxb.java.net/guide/Adding_behaviors.html

Re: using custom builders

Posted by Doug Cutting <cu...@apache.org>.
On 06/05/2012 05:01 PM, Joel VanderWerf wrote:
> This may be what I'm looking for:
>
> org.apache.avro.specific.SpecificData
>
> The getClass() method perhaps can be overridden to map incoming record
> class names to java classes. Not sure if this is the right way to do it
> though. There's also a getClassName() which might be a better method to
> override.
>
> Any thoughts?

Overriding one of the two of these sounds like the right thing. 
getClass() is implemented in terms of getClassName(), so if getClass() 
otherwise does what you want and supplying a different class name is 
sufficient then just override getClassName().  If you need to instead 
override getClass() then you'll probably want to invoke super.getClass() 
for non-record schemas.

I hope this helps.

Doug