I wrote a class which will be converted by xstream into xml .
I added @XStreamAsAttribute to add xmlns as an attribute . But it got added as a nested tag in the output
My class file is as follows
@XStreamAlias("GetConfigurationParametersResponse")
public class GetConfigurationParametersResponse
extends BaseResponse
{
@XStreamAlias("xmlns")
@XStreamAsAttribute
final String xmlns = "http://www.collab.net/teamforge/integratedapp";
@XStreamAlias("xmlns:ns2")
@XStreamAsAttribute
final String ns2="http://www.collab.net/teamforge/integratedapp";
@XStreamImplicit(itemFieldName="ConfigurationParameter")
protected List<ConfigurationParameter> configurationParameter;
public List<ConfigurationParameter> getConfigurationParameter() {
if (configurationParameter == null) {
configurationParameter = new ArrayList<ConfigurationParameter>();
}
return this.configurationParameter;
}
}
The output for this is as follows
<com.collabnet.teamforge.ia.GetConfigurationParametersResponse>
<xmlns>http://www.collab.net/teamforge/integratedapp</xmlns>
<ns2>http://www.collab.net/teamforge/integratedapp</ns2>
</com.collabnet.teamforge.ia.GetConfigurationParametersResponse>
But I need output as
<com.collabnet.teamforge.ia.GetConfigurationParametersResponse xmlns="http://www.collab.net/teamforge/integratedapp" xmlns:ns2="http://www.collab.net/teamforge/integratedapp">
</com.collabnet.teamforge.ia.GetConfigurationParametersResponse>
Please help in finding out where I am going wrong . I followed this tutorial http://x-stream.github.io/annotations-tutorial.html
You probably need to do the following:
xstream.processAnnotations(GetConfigurationParametersResponse.class);
If only the following is being called:
xstream.processAnnotations(BaseResponse.class);
Then you could use the @XStreamInclude
annotation on BaseResponse
as follows:
@XStreamInclude({GetConfigurationParametersResponse.class})
public class BaseResponse {
}