Java標準のXMLシリアライザであるJAXBをPlay Frameworkプロジェクト内で使っていると、こんなランタイムエラーが出てエンティティクラスを解析しそこねることがあります。
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
クラスに同じ名前"name"を持つ2つのプロパティがあります
this problem is related to the following location:
at public java.lang.String Hoge.getName()
at Hoge
this problem is related to the following location:
at public java.lang.String Hoge.name
at Hoge
もちろんHogeクラスにはnameフィールドを作っただけで、同名プロパティだと指摘されているgetName()メソッドなんか作った覚えはありません。
勝手にgetterが…? あ、まさかPlay Frameworkのしわざ?
そうなんです。Playは勝手に各クラスにgetter/setterアクセサをコンパイル後追加してくれるのです。
Play has been designed to generate getter/setter automatically, to ensure compatibility with libraries that expect them to be available at runtime (ORM, Databinder, JSON Binder, etc). If Play detects any user-written getter/setter in the Model, it will not generate getter/setter in order to avoid any conflict.
https://www.playframework.com/documentation/2.2.x/JavaEbean
これを抑止するにはどうすればいいか?
これはアンドキュメンテッドなのですが、
@PropertiesEnhancer.GeneratedAccessor
クラス宣言にこの「アクセサ追加加工済み」を意味するこのアノテーションを付けておくと無視してもらえます。