|
|
|
Ive made such a converter, it's not very nice and polished (I have to copy lot's of functionality of the inner working of the original converter)- but it's working. Feel free to use it, and incorporate in the next release ;-)
Specifically would be the feature of being able to specify some fields as attributes and some as child elements. It sounds like a lot of work - and it probably is. Off the top of my head I can't think of an elegant way to do this either.
I think it would offer a great amount of utility though. Arron Possible approach is to allow to specify list of simple types (int, String, Date, BigInteger, etc) that have registered convertors and will be converted into attributes.
modified version of ReflectionConverter that will marshall any type with an AbstractBasicConverter as an attribute
hi folks,
I just started using XStream today. I am very interested in using this extension (anything that can serialize Strings as attributes is good for me) but don't know quite how to go about actually using it. I guess I need to make AttributeAwareReflectionConverter the default converter. registerConverter() wants an instance of the Converter but I'm stuck since I've no idea of what the last two parameters for the constructor of AttributeAwareReflectionConverter should look like. Anyone got a simple example ? Thanks, Richard Just in case anyone is working on this, please note some limitations of attributes because of the XML specification. Attributes are "normalized" to remove any tabs, newlines, or carriage returns. This could cause serious problems if you have a String with those characters that you would like to preserve.
The only solution is to wrap the attributes in [[CDATA]] and doing so might negate most of the saved space of using attributes instead of entities. For more information see the spec: http://www.w3.org/TR/REC-xml/#AVNormalize and the source of the MXParser: http://www.extreme.indiana.edu/viewcvs/~checkout~/XPP3/java/src/java/mxp1_min/org/xmlpull/mxp1/MXParser.java (look for the code that deals with tabs in the parseAttribute() method) This is now available, but you have to register the types to alias yourself with the new XStream.aliasAttribute(alias,type) method. Reopen if this does not meet your requirements.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I have looked at writing a new StringConverter, but it seems more complicated than that as there is something else that builds the xml String. If someone gives me a pointer I'll contribute the actual work.