当一个类由AspectJ编织时,其字节码(但不其源代码)会收到一个额外注入的静态字段:
private static final org.aspectj.lang.JoinPoint$StaticPart ajc$tjp_0;
MOXy不会将此额外字段视为XmlTransient,并在尝试创建JAXBContext时导致异常:
Caused by: javax.xml.bind.JAXBException:
Exception Description: The class org.aspectj.runtime.reflect.JoinPointImpl$StaticPartImpl requires a zero argument constructor or a specified factory method. Note that non-static inner classes do not have zero argument constructors and are not supported.
- with linked exception:
[Exception [EclipseLink-50001] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.JAXBException
Exception Description: The class org.aspectj.runtime.reflect.JoinPointImpl$StaticPartImpl requires a zero argument constructor or a specified factory method. Note that non-static inner classes do not have zero argument constructors and are not supported.]
根据EclipseLink MOXy example,似乎我应该能够通过创建一个名为@XmlTransient
的文件来创建此字段eclipselink-oxm.xml
,并将该文件放在目录中src/main/resources/META-INF
。但是,这不起作用。
我该怎么办?
<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="${eclipselink.version}">
<java-types>
<java-type name="se.mithlond.services.organisation.model.address.CategorizedAddress">
<java-attributes>
<xml-transient java-attribute="ajc$tjp_0"/>
</java-attributes>
</java-type>
<!--java-type name="org.aspectj.runtime.reflect.JoinPointImpl$StaticPartImpl" xml-transient="true" />
<java-type name="org.aspectj.runtime.reflect.JoinPointImpl" xml-transient="true" / -->
</java-types>
</xml-bindings>