[Simple-support] How do you access field annotations from a custom Converter?
Brought to you by:
niallg
|
From: James B. Jr. <de...@gm...> - 2012-02-20 00:52:14
|
For some of my more complex data structures, I need to write my own
Converters. For instance, say I have a List<List<String>> that I need to
marshall. I've written the following:
class WorldObject {
@Element(name="vector-names")
@Convert(ListListConverter.class)
private List<List<String>> vectorNames;
/** Constructor and other details elided... **/
}
Along with the ListListConverter (I've left out the unmarshaller for the
moment):
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();
}
}
This setup works fine, and produces the XML I want. I would, however, like
to have access to the `@Element` annotation's `name` field so that I can
give the tags the specified name (in this case, `"vector-names"`) rather
than the default name (`"list-list-string"`). This is how marshalling works
for all the types that Simple handles out of the box, so there must be a
way to access that data from a custom Converter.
How can I accomplish this?
Thank you very much,
--James
|