Java Code Examples for com.thoughtworks.xstream.XStream#processAnnotations()

The following examples show how to use com.thoughtworks.xstream.XStream#processAnnotations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Parser.java    From KJFrameForAndroid with Apache License 2.0 6 votes vote down vote up
public static <T> T xmlToBean(Class<T> type, String xml) {
    T data = null;
    try {
        XStream xStream = new XStream(new DomDriver("UTF-8"));
        xStream.processAnnotations(type);
        data = (T) xStream.fromXML(xml);
    } catch (Exception e) {
        try {
            data = type.newInstance();
        } catch (Exception ee) {
        } finally {
            Log.e("kymjs", "xml解析异常");
        }
    }
    return data;
}
 
Example 2
Source File: XStreamTransformer.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
private static XStream configWxCpXmlMessage() {
  XStream xstream = XStreamInitializer.getInstance();

  xstream.processAnnotations(WxCpXmlMessage.class);
  xstream.processAnnotations(WxCpXmlMessage.ScanCodeInfo.class);
  xstream.processAnnotations(WxCpXmlMessage.SendPicsInfo.class);
  xstream.processAnnotations(WxCpXmlMessage.SendPicsInfo.Item.class);
  xstream.processAnnotations(WxCpXmlMessage.SendLocationInfo.class);
  return xstream;
}
 
Example 3
Source File: Object2Xml.java    From ExamStack with GNU General Public License v2.0 5 votes vote down vote up
public static <T> T toBean(String xmlStr,Class<T> cls){
	XStream xstream=new XStream(new DomDriver());
	xstream.processAnnotations(cls);
	@SuppressWarnings("unchecked")
	T obj=(T)xstream.fromXML(xmlStr);
	return obj;
}
 
Example 4
Source File: XmlUtilsTest.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Test
	public void testPersonListFormEmptyElement(){
//		XStream xstream = new XStream(new DomDriver());
		XStream xstream = new XStream();
		xstream.processAnnotations(TestPersonAnnotationList.class);
		xstream.processAnnotations(TestPersonAnnotation.class);
		xstream.processAnnotations(TestPerson.class);
//		xstream.registerConverter(new EmptyTestPersonAnnotationConverter());
		
		TestPersonAnnotation hh = new TestPersonAnnotation();
		hh.setUserName("hanhan");
		hh.setAge(30);
		TestPerson parent = new TestPerson();
//		parent.setAge(11);
		hh.setParent(null);
		
		TestPersonAnnotationList list = new TestPersonAnnotationList();
		list.list.add(hh);
		String xmlStr = xstream.toXML(list);
		/*StringWriter sw = new StringWriter();
		PrettyPrintWriter writer = new CompactWriter(sw);
		xstream.marshal(list, writer);
		String xmlStr = sw.toString();*/
		
		System.out.println("testPersonListFormEmptyElement xml:\n " + xmlStr);
		
		xmlStr = XmlUtils.toXML(Lists.newArrayList(hh), "list", ArrayList.class, 
				"person", TestPersonAnnotation.class);
		System.out.println("testPersonListFormEmptyElement xml22:\n " + xmlStr);
		
	}
 
Example 5
Source File: GatfTestCaseExecutorUtil.java    From gatf with Apache License 2.0 5 votes vote down vote up
public static GatfExecutorConfig getConfig(InputStream resource) {
    XStream xstream = new XStream(new DomDriver("UTF-8"));
    XStream.setupDefaultSecurity(xstream);
    xstream.allowTypes(new Class[] {GatfExecutorConfig.class, GatfTestDataConfig.class, GatfTestDataProvider.class, 
            SeleniumDriverConfig.class, GatfTestDataSourceHook.class, GatfTestDataSource.class});
    xstream.processAnnotations(new Class[] {GatfExecutorConfig.class, GatfTestDataConfig.class, GatfTestDataProvider.class, 
            SeleniumDriverConfig.class, GatfTestDataSourceHook.class, GatfTestDataSource.class});
    xstream.alias("gatf-testdata-source", GatfTestDataSource.class);
    xstream.alias("gatf-testdata-provider", GatfTestDataProvider.class);
    xstream.alias("gatf-testdata-source-hook", GatfTestDataSourceHook.class);
    xstream.alias("gatfTestDataConfig", GatfTestDataConfig.class);
    xstream.alias("seleniumDriverConfigs", SeleniumDriverConfig[].class);
    xstream.alias("seleniumDriverConfig", SeleniumDriverConfig.class);
    xstream.alias("args", String[].class);
    xstream.alias("arg", String.class);
    xstream.alias("testCaseHooksPaths", String[].class);
    xstream.alias("testCaseHooksPath", String.class);
    xstream.alias("queryStrs", String[].class);
    xstream.alias("queryStr", String.class);
    xstream.alias("distributedNodes", String[].class);
    xstream.alias("distributedNode", String.class);
    xstream.alias("ignoreFiles", String[].class);
    xstream.alias("ignoreFile", String.class);
    xstream.alias("orderedFiles", String[].class);
    xstream.alias("orderedFile", String.class);
    xstream.alias("string", String.class);
    xstream.alias("seleniumScripts", String[].class);
    xstream.alias("seleniumScript", String.class);

    GatfExecutorConfig configuration = (GatfExecutorConfig) xstream.fromXML(resource);
    configuration.setJavaVersion(System.getProperty("java.version"));
    return configuration;
}
 
Example 6
Source File: XmlBeanJsonConverUtil.java    From aaden-pay with Apache License 2.0 5 votes vote down vote up
/**
 * 把XML转成对象
 *
 * @param xmlStr
 * @param clss
 *            是转换对象的所有对象的list列表如aa.class
 * @return Object
 */
@SuppressWarnings("unchecked")
public static <T> T xmlStringToBean(String xmlStr, List<Class<T>> clss) {
	XStream xstream = new XStream(new DomDriver());
	for (Class<T> cls : clss) {
		xstream.processAnnotations(cls);
	}
	xstream.autodetectAnnotations(true);
	return (T) xstream.fromXML(xmlStr);
}
 
Example 7
Source File: XmlBeanJsonConverUtil.java    From aaden-pay with Apache License 2.0 5 votes vote down vote up
/**
 * 把XML转成对象
 *
 * @param xmlStr
 * @return Object
 */
@SuppressWarnings("unchecked")
public static <T> T xmlStringToBean(String xmlStr, Class<T> cls) {
	XStream xstream = new XStream(new DomDriver());
	xstream.processAnnotations(cls);
	xstream.autodetectAnnotations(true);
	return (T) xstream.fromXML(xmlStr);
}
 
Example 8
Source File: GatfTestGeneratorUtil.java    From gatf with Apache License 2.0 5 votes vote down vote up
public static String getConfigStr(GatfConfiguration configuration)
{
	XStream xstream = new XStream(new DomDriver("UTF-8"));
       XStream.setupDefaultSecurity(xstream);
       xstream.allowTypes(new Class[]{GatfConfiguration.class});
	xstream.processAnnotations(new Class[]{GatfConfiguration.class});
	xstream.alias("testPaths", String[].class);
	xstream.alias("testPath", String.class);
	xstream.alias("soapWsdlKeyPairs", String[].class);
	xstream.alias("soapWsdlKeyPair", String.class);
	xstream.alias("string", String.class);
	
	return xstream.toXML(configuration);
}
 
Example 9
Source File: XStreamMarshaller.java    From tutorials with MIT License 5 votes vote down vote up
public XStreamMarshaller() {
    super();

    xstream = new XStream();
    xstream.autodetectAnnotations(true);
    xstream.processAnnotations(Foo.class);
}
 
Example 10
Source File: XmlApiResponse.java    From engage-api-client with Apache License 2.0 5 votes vote down vote up
private XStream prepareXStream(Class<? extends ApiResult> resultClass) {
	XmlApiReflectionProvider reflectionProvider = new XmlApiReflectionProvider(resultClass);
	XStream xStream = xStreamFactory.createXStream(reflectionProvider);
	
	xStream.processAnnotations(XmlApiResponseEnvelope.class);		
	xStream.addDefaultImplementation(resultClass, ApiResponse.class);
	xStream.processAnnotations(resultClass);

	return xStream;
}
 
Example 11
Source File: XmlUtil.java    From EasyEE with MIT License 5 votes vote down vote up
/**
 * java bean 转化为xml
 * 
 * @param object
 * @param objClass
 * @return
 */
public static String parseBeanToXml(Object object, Class<?> objClass) {
	String xmlString = "";
	XStream xStream = new XStream(new DomDriver());
	xStream.processAnnotations(objClass);
	xmlString = xStream.toXML(object);
	xmlString = header + xmlString;
	return xmlString;
}
 
Example 12
Source File: XStreamXMLDeserializer.java    From vraptor4 with Apache License 2.0 5 votes vote down vote up
/**
 * @return an xstream instance already configured.
 */
public XStream getConfiguredXStream(Method javaMethod, Class<?>[] types) {
	XStream xStream = builder.recursive().xmlInstance();

	xStream.processAnnotations(types);

	aliasParams(javaMethod, xStream);
	return xStream;
}
 
Example 13
Source File: XStreamTransformer.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
private static XStream config_WxMpXmlOutTextMessage() {
  XStream xstream = XStreamInitializer.getInstance();
  xstream.processAnnotations(WxMpXmlOutMessage.class);
  xstream.processAnnotations(WxMpXmlOutTextMessage.class);
  return xstream;
}
 
Example 14
Source File: XmlUtil.java    From EasyEE with MIT License 4 votes vote down vote up
public static Object fromXml(String xml, Class<?> objClass) {
	XStream xStream = new XStream();
	xStream.processAnnotations(objClass);
	return xStream.fromXML(xml);
}
 
Example 15
Source File: XStreamTransformer.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
private static XStream config_WxCpXmlOutVoiceMessage() {
  XStream xstream = XStreamInitializer.getInstance();
  xstream.processAnnotations(WxCpXmlOutMessage.class);
  xstream.processAnnotations(WxCpXmlOutVoiceMessage.class);
  return xstream;
}
 
Example 16
Source File: XmlUtil.java    From EasyEE with MIT License 4 votes vote down vote up
public static Object fromXml(String xml, Class<?> objClass) {
	XStream xStream = new XStream();
	xStream.processAnnotations(objClass);
	return xStream.fromXML(xml);
}
 
Example 17
Source File: XstreamUtils.java    From osmanthus with Apache License 2.0 4 votes vote down vote up
public static KnowledgePackage xml2Strategy(String content) {
    XStream xs = new XStream();
    xs.processAnnotations(SUPPORT_CLASSES);
    return (KnowledgePackage) xs.fromXML(content);
}
 
Example 18
Source File: MessageUtils.java    From wechat-core with Apache License 2.0 2 votes vote down vote up
/**
 * 视频消息转xml
 *
 * @param videoMessage 视频消息对象
 * @return xml字符串
 */
public static String videoMessageToXml(VideoResponseMessage videoMessage) {
    XStream xstream = newXStreamInstance();
    xstream.processAnnotations(videoMessage.getClass());
    return xstream.toXML(videoMessage);
}
 
Example 19
Source File: MessageUtils.java    From wechat-core with Apache License 2.0 2 votes vote down vote up
/**
 * 将相应消息转换成xml字符串
 *
 * @param baseResponseMessage
 * @return
 */
public static String messageToXml(BaseResponseMessage baseResponseMessage) {
    XStream xStream = newXStreamInstance();
    xStream.processAnnotations(baseResponseMessage.getClass());
    return xStream.toXML(baseResponseMessage);
}
 
Example 20
Source File: MessageUtils.java    From wechat-core with Apache License 2.0 2 votes vote down vote up
/**
 * 文本消息转xml
 *
 * @param textMessage 文本消息对象
 * @return xml字符串
 */
public static String textMessageToXml(TextResponseMessage textMessage) {
    XStream xstream = newXStreamInstance();
    xstream.processAnnotations(textMessage.getClass());
    return xstream.toXML(textMessage);
}