Simple (http://simple.sourceforge.net/) ライブラリを使用して、Java で XML データをマーシャリング/アンマーシャリングしています。より複雑なデータ構造の一部については、独自のコンバーターを作成する必要があります。たとえば、List<List<String>>
マーシャリングする必要がある があるとします。私は次のように書いています:
class WorldObject {
@Element(name="vector-names")
@Convert(ListListConverter.class)
private List<List<String>> vectorNames;
/** Constructor and other details ... **/
}
ListListConverter とともに (アンマーシャラーは今のところ省いています):
class ListListConverter implements Converter<List<List<String>>> {
@Override
public List<List<String>> read(InputNode node) throws Exception {
// stub
return null;
}
@Override
public void write(OutputNode node, List<List<String>> value)
throws Exception {
node.setName("list-list-string");
for (List<String> list : value) {
OutputNode subList = node.getChild("list-string");
for (String str : list) {
OutputNode stringNode = subList.getChild("string");
stringNode.setValue(str);
}
subList.commit();
}
node.commit();
}
}
この設定は問題なく動作し、必要な XML が生成されます。ただし、タグにデフォルト名 ( ) ではなく指定した名前 (この場合は ) を付けることができるように、@Element
注釈のフィールドにアクセスしたいと考えています。これは、Simple がすぐに使用できるすべての型に対してマーシャリングが機能する方法であるため、カスタム Converter からそのデータにアクセスする方法が必要です。name
"vector-names"
"list-list-string"
どうすればこれを達成できますか?