XStreamMarshaller support for aliasField ?
Hello,
I need to rename an attribute before writing it to XML.
Basically, I would like to do http://xstream.codehaus.org/alias-tu...field_aliasing.
Exemple : my class
Code:
public class Document implements Serializable {
private String canalOperateur;
should produce the following XML :
Code:
<document>
<cOperateur>
But I cannot configure aliasField information in XStream.
I must use @XStreamAlias annotation to do this.
Is there a way to do it without annotation (only in spring configuration ?)
Thanks !
XStream double underline handling
Hello,
Just FYI , in case someone has the same problem.
I wanted to serialize a java class to XML with XStream.
I needed to generated an XML element with one underline (canal_operateur), but XStream adds a second underline in the xml element name.
So how to keep only one underline ?
With the default configuration for this class :
Code:
@XStreamAlias("document")
@SuppressWarnings("serial")
public class Document implements Serializable {
private String typedoc;
private Fichier fichier;
@XStreamAlias("canal_operateur")
private String canalOperateur;
}
XStream doubles the underline :
Code:
<document>
<canal__operateur>canal</canal__operateur>
<commentaire>commentaire</commentaire>
<metadonnees/>
</document>
You need the following configuration to override default behaviour and keep only one underline :
Code:
<bean id="marshaller" class="org.springframework.oxm.xstream.AnnotationXStreamMarshaller">
<property name="streamDriver">
<bean class="com.thoughtworks.xstream.io.xml.XppDriver">
<constructor-arg>
<bean class="com.thoughtworks.xstream.io.xml.XmlFriendlyReplacer">
<constructor-arg index="0" value="_-"/>
<constructor-arg index="1" value="_"/>
</bean>
</constructor-arg>
</bean>
</property>
<property name="annotatedClasses">
<list>
<value>com.natixis.gedig.collecteur.writer.injecteur.Document</value>
</list>
</property>
</bean>
See also : http://markmail.org/message/ito56wubohai3w45