@@ -1,13 +1,19 @@ | |||||
package me.chanjar.weixin.cp.util.xml; | package me.chanjar.weixin.cp.util.xml; | ||||
import com.thoughtworks.xstream.XStream; | |||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer; | |||||
import me.chanjar.weixin.cp.bean.*; | |||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.util.HashMap; | import java.util.HashMap; | ||||
import java.util.Map; | import java.util.Map; | ||||
import com.thoughtworks.xstream.XStream; | |||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer; | |||||
import me.chanjar.weixin.cp.bean.WxCpXmlMessage; | |||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutImageMessage; | |||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage; | |||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutNewsMessage; | |||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage; | |||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutVideoMessage; | |||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutVoiceMessage; | |||||
public class XStreamTransformer { | public class XStreamTransformer { | ||||
protected static final Map<Class, XStream> CLASS_2_XSTREAM_INSTANCE = configXStreamInstance(); | protected static final Map<Class, XStream> CLASS_2_XSTREAM_INSTANCE = configXStreamInstance(); | ||||
@@ -38,7 +44,7 @@ public class XStreamTransformer { | |||||
} | } | ||||
/** | /** | ||||
* pojo -> xml | |||||
* pojo -> xml. | |||||
*/ | */ | ||||
public static <T> String toXml(Class<T> clazz, T object) { | public static <T> String toXml(Class<T> clazz, T object) { | ||||
return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object); | return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object); | ||||
@@ -1,12 +1,16 @@ | |||||
package cn.binarywang.wx.miniapp.util.xml; | package cn.binarywang.wx.miniapp.util.xml; | ||||
import java.io.InputStream; | |||||
import java.util.ArrayList; | |||||
import java.util.Arrays; | |||||
import java.util.HashMap; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
import cn.binarywang.wx.miniapp.bean.WxMaMessage; | import cn.binarywang.wx.miniapp.bean.WxMaMessage; | ||||
import com.thoughtworks.xstream.XStream; | import com.thoughtworks.xstream.XStream; | ||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer; | import me.chanjar.weixin.common.util.xml.XStreamInitializer; | ||||
import java.io.InputStream; | |||||
import java.util.*; | |||||
/** | /** | ||||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||
*/ | */ | ||||
@@ -45,7 +49,7 @@ public class XStreamTransformer { | |||||
* @param clz 类型 | * @param clz 类型 | ||||
* @param xStream xml解析器 | * @param xStream xml解析器 | ||||
*/ | */ | ||||
private static void register(Class<?> clz, XStream xStream) { | |||||
public static void register(Class<?> clz, XStream xStream) { | |||||
CLASS_2_XSTREAM_INSTANCE.put(clz, xStream); | CLASS_2_XSTREAM_INSTANCE.put(clz, xStream); | ||||
} | } | ||||
@@ -1,11 +1,22 @@ | |||||
package me.chanjar.weixin.mp.util.xml; | package me.chanjar.weixin.mp.util.xml; | ||||
import java.io.InputStream; | |||||
import java.util.ArrayList; | |||||
import java.util.Arrays; | |||||
import java.util.HashMap; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
import com.thoughtworks.xstream.XStream; | import com.thoughtworks.xstream.XStream; | ||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer; | import me.chanjar.weixin.common.util.xml.XStreamInitializer; | ||||
import me.chanjar.weixin.mp.bean.message.*; | |||||
import java.io.InputStream; | |||||
import java.util.*; | |||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; | |||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutImageMessage; | |||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMusicMessage; | |||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutNewsMessage; | |||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutTextMessage; | |||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutTransferKefuMessage; | |||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutVideoMessage; | |||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutVoiceMessage; | |||||
public class XStreamTransformer { | public class XStreamTransformer { | ||||
private static final Map<Class<?>, XStream> CLASS_2_XSTREAM_INSTANCE = new HashMap<>(); | private static final Map<Class<?>, XStream> CLASS_2_XSTREAM_INSTANCE = new HashMap<>(); | ||||
@@ -22,7 +33,7 @@ public class XStreamTransformer { | |||||
} | } | ||||
/** | /** | ||||
* xml -> pojo | |||||
* xml -> pojo. | |||||
*/ | */ | ||||
@SuppressWarnings("unchecked") | @SuppressWarnings("unchecked") | ||||
public static <T> T fromXml(Class<T> clazz, String xml) { | public static <T> T fromXml(Class<T> clazz, String xml) { | ||||
@@ -37,24 +48,24 @@ public class XStreamTransformer { | |||||
} | } | ||||
/** | /** | ||||
* pojo -> xml | |||||
* pojo -> xml. | |||||
*/ | */ | ||||
public static <T> String toXml(Class<T> clazz, T object) { | public static <T> String toXml(Class<T> clazz, T object) { | ||||
return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object); | return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object); | ||||
} | } | ||||
/** | /** | ||||
* 注册扩展消息的解析器 | |||||
* 注册扩展消息的解析器. | |||||
* | * | ||||
* @param clz 类型 | * @param clz 类型 | ||||
* @param xStream xml解析器 | * @param xStream xml解析器 | ||||
*/ | */ | ||||
private static void register(Class<?> clz, XStream xStream) { | |||||
public static void register(Class<?> clz, XStream xStream) { | |||||
CLASS_2_XSTREAM_INSTANCE.put(clz, xStream); | CLASS_2_XSTREAM_INSTANCE.put(clz, xStream); | ||||
} | } | ||||
/** | /** | ||||
* 会自动注册该类及其子类 | |||||
* 会自动注册该类及其子类. | |||||
* | * | ||||
* @param clz 要注册的类 | * @param clz 要注册的类 | ||||
*/ | */ | ||||
@@ -1,12 +1,16 @@ | |||||
package me.chanjar.weixin.open.util.xml; | package me.chanjar.weixin.open.util.xml; | ||||
import java.io.InputStream; | |||||
import java.util.ArrayList; | |||||
import java.util.Arrays; | |||||
import java.util.HashMap; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
import com.thoughtworks.xstream.XStream; | import com.thoughtworks.xstream.XStream; | ||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer; | import me.chanjar.weixin.common.util.xml.XStreamInitializer; | ||||
import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | ||||
import java.io.InputStream; | |||||
import java.util.*; | |||||
/** | /** | ||||
* @author <a href="https://github.com/007gzs">007</a> | * @author <a href="https://github.com/007gzs">007</a> | ||||
*/ | */ | ||||
@@ -18,7 +22,7 @@ public class XStreamTransformer { | |||||
} | } | ||||
/** | /** | ||||
* xml -> pojo | |||||
* xml -> pojo. | |||||
*/ | */ | ||||
@SuppressWarnings("unchecked") | @SuppressWarnings("unchecked") | ||||
public static <T> T fromXml(Class<T> clazz, String xml) { | public static <T> T fromXml(Class<T> clazz, String xml) { | ||||
@@ -33,24 +37,24 @@ public class XStreamTransformer { | |||||
} | } | ||||
/** | /** | ||||
* pojo -> xml | |||||
* pojo -> xml. | |||||
*/ | */ | ||||
public static <T> String toXml(Class<T> clazz, T object) { | public static <T> String toXml(Class<T> clazz, T object) { | ||||
return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object); | return CLASS_2_XSTREAM_INSTANCE.get(clazz).toXML(object); | ||||
} | } | ||||
/** | /** | ||||
* 注册扩展消息的解析器 | |||||
* 注册扩展消息的解析器. | |||||
* | * | ||||
* @param clz 类型 | * @param clz 类型 | ||||
* @param xStream xml解析器 | * @param xStream xml解析器 | ||||
*/ | */ | ||||
private static void register(Class<?> clz, XStream xStream) { | |||||
public static void register(Class<?> clz, XStream xStream) { | |||||
CLASS_2_XSTREAM_INSTANCE.put(clz, xStream); | CLASS_2_XSTREAM_INSTANCE.put(clz, xStream); | ||||
} | } | ||||
/** | /** | ||||
* 会自动注册该类及其子类 | |||||
* 会自动注册该类及其子类. | |||||
* | * | ||||
* @param clz 要注册的类 | * @param clz 要注册的类 | ||||
*/ | */ | ||||