You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Marek Romanowski (Jira)" <ji...@apache.org> on 2020/11/03 21:05:00 UTC

[jira] [Commented] (AVRO-2544) Allow avro-maven-plugin to generate Java classes that implement interfaces

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

Marek Romanowski commented on AVRO-2544:
----------------------------------------

I hope it will be helpful for others if I'll leave a comment here that I've created maven plugin for exactly this case - [https://github.com/tunguski/interfacer].

It goes through auto generated classes and check do they conform to interfaces found on classpath in specific package. If yes, interface is added to the class. It works with generic interfaces, at least in basic examples I had to deal with.
  
{code:xml}
<!-- 
  post process avro generated sources and add interfaces from package
  pl.matsuo.interfacer.showcase to every generated class that has 
  all methods from specific interface
 -->
<plugin>
    <groupId>pl.matsuo.interfacer</groupId>
    <artifactId>interfacer-maven-plugin</artifactId>
    <version>0.0.6</version>
    <executions>
        <execution>
            <configuration>
                <interfacesDirectory>${project.basedir}/src/main/java</interfacesDirectory>
                <interfacePackage>pl.matsuo.interfacer.showcase</interfacePackage>
            </configuration>
            <goals>
                <goal>add-interfaces</goal>
            </goals>
        </execution>
    </executions>
</plugin>
{code}

> Allow avro-maven-plugin to generate Java classes that implement interfaces 
> ---------------------------------------------------------------------------
>
>                 Key: AVRO-2544
>                 URL: https://issues.apache.org/jira/browse/AVRO-2544
>             Project: Apache Avro
>          Issue Type: Wish
>          Components: java
>    Affects Versions: 1.9.0
>            Reporter: Michael Snell
>            Priority: Major
>
> Currently Java code generated by the avro-maven-plugin  implements the org.apache.avro.specific.SpecificRecord interface, but there is no ability to have the generated code implement additional interfaces, which would make it possible to improve type-safety and readability.
> Similar to the already existing @java-class annotation ([https://avro.apache.org/docs/current/idl.html#minutiae_annotations]) I suggest adding a @java-implements annotation that could be added to a record definition:
> {code:java}
> @java-implements("an.example.JavaInterface")
> record AnExampleRecord {
> ...{code}
> This would be used by the avro-maven-plugin when generating Java code such that the result implements both SpecificRecord and the specified interface:
> {code:java}
> public class AnExampleRecord extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord , an.example.JavaInterface{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)