Re: [Simple-support] How do you access field annotations from a custom Converter?
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2012-02-20 09:16:23
|
the outputnode contains the name, see getName()
--- On Sun, 19/2/12, James Brawn, Jr. <de...@gm...> wrote:
From: James Brawn, Jr. <de...@gm...>
Subject: [Simple-support] How do you access field annotations from a custom Converter?
To: sim...@li...
Received: Sunday, 19 February, 2012, 4:52 PM
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
-----Inline Attachment Follows-----
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
-----Inline Attachment Follows-----
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|