我编写了一个类,它将被xstream转换成xml。
我添加了@XStreamAsAttribute作为属性添加xmlns。但是它作为嵌套标记添加到输出中。
我的类文件如下
@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;
}
}这方面的输出如下
<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>但我需要输出
<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>请帮忙找出我哪里出错了。我遵循了本教程http://x-stream.github.io/annotations-tutorial.html
发布于 2013-08-07 15:19:04
您可能需要执行以下操作:
xstream.processAnnotations(GetConfigurationParametersResponse.class);如果只需要调用以下内容:
xstream.processAnnotations(BaseResponse.class);然后,您可以将@XStreamInclude注释用于BaseResponse,如下所示:
@XStreamInclude({GetConfigurationParametersResponse.class})
public class BaseResponse {
}发布于 2015-08-11 21:10:34
对我有用的是:
xstream.autodetectAnnotations(true);https://stackoverflow.com/questions/18106619
复制相似问题