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

Julian Peeters commented on AVRO-1703:
--------------------------------------

You can guess that this is an issue for me too, thanks for the attention.


{quote}
I used the IndexedRecord interface instead, which seems to fit nicely with the 
idea of using Scala case classes
{quote}

If one doesn't mind an extra runtime dependency, 
https://github.com/sksamuel/avro4s uses an approach like this, using a type 
class to convert the case class instance to a GenericRecord when Java interop 
is needed. This usually works great, and is much cleaner than working with 
regular GenericRecords. But there a few issues with this:

    1) Sometimes a pre-existing project has chosen to use a framework's 
Specific API
    2) Sometimes a framework *only* offers a Specific API (e.g. Scalding, AFAIK)

Although I haven't looked into it, there *may* be a way to use a similar type 
class strategy with https://github.com/oedura/scavro (whose Scala classes can 
also generated by avrohugger). This, if even possible, would carry over 
Scavro's benefits of being able to use immutable fields, but again at the cost 
of an extra runtime dependency.

Would certainly prefer a fix "at the source".

Full disclosure: I'd just like to use Scala with the Specific API, even if it 
obsoletes avrohugger.





> Specific record should not only be determined by presence of SCHEMA$ field
> --------------------------------------------------------------------------
>
>                 Key: AVRO-1703
>                 URL: https://issues.apache.org/jira/browse/AVRO-1703
>             Project: Avro
>          Issue Type: Improvement
>            Reporter: Marius Soutier
>              Labels: starter
>
> I want to use Avro from Scala, i.e. generate case classes from an Avro 
> schema. So far this is working fine except for one thing - fields in Scala 
> classes are always private. This doesn't work with Avro SpecificRecords (at 
> least when inferring the schema from the class) and results in the following 
> exception:
> org.apache.avro.AvroRuntimeException: java.lang.IllegalAccessException: Class 
> org.apache.avro.specific.SpecificData can not access a member of class 
> <my.Class> with modifiers "private"
> The exception is thrown from the following line in 
> org.apache.avro.specific.SpecificData:
> schema = (Schema)(c.getDeclaredField("SCHEMA$").get(null));
> My suggestion would be to additionally check for a method called `getSchema` 
> and read the schema from that method.



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

Reply via email to