com.gitee.easyopen.serializer.XmlResultSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of easyopen Show documentation
Show all versions of easyopen Show documentation
一个简单易用的接口开放平台,平台封装了常用的参数校验、结果返回等功能,开发者只需实现业务代码即可。https://gitee.com/durcframework/easyopen
package com.gitee.easyopen.serializer;
import com.gitee.easyopen.ApiResult;
import com.gitee.easyopen.ResultSerializer;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.naming.NoNameCoder;
import com.thoughtworks.xstream.io.xml.StaxDriver;
/**
* 序列化成xml
* @author tanghc
*/
public class XmlResultSerializer implements ResultSerializer {
private static XStream xStream = new XStream(new StaxDriver(new NoNameCoder()));
static {
xStream.processAnnotations(ApiResult.class);
xStream.aliasSystemAttribute(null, "class");
}
@Override
public String serialize(Object obj) {
return getXStream().toXML(obj);
}
public XStream getXStream() {
return xStream;
}
}