2

JDK5ベースのアプリでJAXBを使用しています。

XMLマーシャリングは副次的な機能であるため、POJOモデルの注釈は除外されます。除外する必要のあるフィールドはtransient(javaキーワード)です。

Marshalerそれらのフィールドを無視するようにを構成する方法はありますか?

POJOをXMLにシリアル化するために使用するコードは次のとおりです。

JAXBContext context = JAXBContext.newInstance(BasePOJO.class, target.getClass());

JAXBElement<WsResponse> model = new JAXBElement<BasePOJO>(
        new QName(target.getClass().getSimpleName()), 
        (Class<BasePOJO>) target.getClass(), 
        (BasePOJO)target
    );

Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(model, os);

シリアル化する必要があるサンプルPOJO:

public class APOJO extends BasePOJO {
  private Long id;
  private String desc;
  private transient String aFieldToIgnore;

  //and the accessors[...]
}
4

1 に答える 1

1

@XmlTransientフィールドに注釈を使用せずにこれを行う方法があるとは思いません。

実際にカスタマイズできるのは、XSD でバインディング ファイルまたはインライン バインディングを使用することだけです。

可能なことについては、リファレンスを確認してください: http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.5/tutorial/doc/JAXBUsing4.html

于 2013-03-18T14:52:21.227 に答える