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[...]
}