parent
s のリストを含む aをシリアライズしようとしていますchild
。これらchild
の s にはactivated
ブール型フィールドがあり、結果の XML には属性が設定されたchild
swichのみが含まれるようにしたいactivated
true
オブジェクトをコピーし、プロセスで sparent
をフィルタリングすることでこれを行うことができchild
ます (最後にこれを行うこともできます) が、SimpleXML をカスタマイズして同じ結果を得ることができるかどうか疑問に思っています。
編集
ollo からの応答を使用しました。Converter
子クラスの元の注釈を使用するように実装を変更しました。
新しいConverter
実装:
public class ChildConverter implements Converter<Child>
{
@Override
public Child read(InputNode node) throws Exception
{
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void write(OutputNode node, Child value) throws Exception
{
if( value.isActived() == true ) // Check if 'activated' flag is set
{
// Set valus of the child
//We don't use an annotation strategy for this persister to avoid
//a recursive call to this method.
Serializer serializer = new Persister();
serializer.write(value, node);
}
else
{
node.remove(); // Remove the node since we don't need it
}
}
}