アップデート
MOXy には、GlassFish などの OSGi 環境でマーシャル/アンマーシャル メソッドの呼び出しを妨げるバグ ( http://bugs.eclipse.org/412417を参照) がありました。これは、EclipseLink 2.3.3、2.4.3、2.5.1、および 2.6.0 ストリームで修正されました。2013 年 7 月 10 日以降、次のリンクからナイトリー ビルドをダウンロードできます。
同じイベントが 2 回呼び出される問題を再現できませんでした。この問題を示すコード例がある場合は、私のブログを通じて私との電子メールでの会話を開始してください。
XMLバインディング
beforeMarshal
メソッドが 1 回ではなく 2 回呼び出されている場合は、JAXB (JSR-222) プロバイダーとして EclipseLink MOXy ではなく参照実装を使用しています。
デモコード
import javax.xml.bind.*;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Foobar.class);
System.out.println(jc.getClass());
Foobar foobar = new Foobar();
Marshaller marshaller = jc.createMarshaller();
marshaller.marshal(foobar, System.out);
}
}
出力 - JAXB リファレンス実装
class com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl
beforeMarshal fired
beforeMarshal fired
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><foobar/>
出力 - EclipseLink MOXy
class org.eclipse.persistence.jaxb.JAXBContext
beforeMarshal fired
<?xml version="1.0" encoding="UTF-8"?>
<foobar/>
MOXy を JAXB プロバイダーとして有効にするにはjaxb.properties
、次のエントリを使用してドメイン モデルと同じパッケージに呼び出されるファイルを含める必要があります ( http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-asを参照)。 -your.html )。
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
JSONバインディング
MOXy は、XML と JSON のバインドに同じ配管を使用します。これは、両方で同じイベント動作が見られることを意味します。イベントが表示されない場合は、MOXy 以外の JSON バインディング プロバイダーを使用してください。