I don't want to apply a converter to the top-level class. That would require too much work whenever a new field is added. Adding a simple annotation to a single variable is already a compromise. I am trying to clean up the current logic which is not maintainable.
So basically Converters do not have access to the field name of the variable they are annotating? I will only be annotating Java primitives (although I can switch to the class equivalents) and Strings. Back to the XSL route. I already created an XSLT that output the format that I require, but according the the example, it seems like the transformation occurs parallel to the marshal call. I need the transformation to occur after marshaling has occurred. I have not actually run the code, but that is my take on the code. Cheers, Ivan On Fri, Jul 19, 2013 at 11:11 AM, Jörg Schaible <joerg.schai...@gmx.de>wrote: > Hi Ivan, > > Ivan Brusic wrote: > > > I inherited a project that was built using XStream 1.2.2. It will be > > possible upgrade to 1.4.4, but there is no testing around XStream, so I > > would need to do a lot of manual testing. > > > > Trying to come up with a more automatic way of creating output. The XML > is > > normalized in standard XML fields. For example: > > String foo = "bar"; > > > > results in > > > > <field name="foo">bar</field> > > > > Although I would like an automatic way to have this format for all > > attributes way, I was not able to find an easy solution. I then looked at > > annotating classes in order to use a custom converter: > > > > @XStreamConverter(MyFieldConverter.class) > > String foo; > > > > However, it seems I cannot access the variable name "foo". > > You have registered a local converter for a String. Class java.lang.String > has no member "foo". Definitely. > > > I can see the > > value in the writer's element stack, but the stack is not publicly > > accessible. Is there a way to retrieve the field name? > > If you declare the converter for the proper type ... ;-) > > > Another option I can see is to post-process the XML using XSLT. Is it > > possible to associate an XSLT with a class? > > > > If my code has: > > xstream.marshal(obj, new CompactWriter(out)); > > can I associate an XSLT with obj's class? If not, do I setup the > > traxsource/transformer as shown in the example before my marshal call? > > I'd go with a converter ... > > Cheers, > Jörg > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > >