对返回结果中以$n结尾的节点的序列化做了优化

This commit is contained in:
jinyu 2015-06-15 09:07:35 +08:00
parent 5ffc7f2a98
commit 692a2b8129
11 changed files with 137 additions and 223 deletions

View File

@ -3,8 +3,11 @@ package com.foxinmy.weixin4j.util;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;
/** /**
* @title 反射工具类 * @title 反射工具类
@ -214,4 +217,20 @@ public class ReflectionUtil {
} }
return null; return null;
} }
public static Set<Field> getAllField(Class<?> clazz) {
Set<Field> fieldSet = new HashSet<Field>();
while (clazz != Object.class) {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
int modifier = field.getModifiers();
if (Modifier.isFinal(modifier) || Modifier.isStatic(modifier)) {
continue;
}
fieldSet.add(field);
}
clazz = clazz.getSuperclass();
}
return fieldSet;
}
} }

View File

@ -4,9 +4,23 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.util.regex.Pattern;
/**
* 对$n结尾的节点注解
*
* @className ListsuffixResult
* @author jy
* @date 2015年6月15日
* @since JDK 1.7
* @see
*/
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface ListsuffixResult { public @interface ListsuffixResult {
String[] value() default { DEFAULT_REGEX };
public final static String DEFAULT_REGEX = "(_\\d)$";
public final static Pattern DEFAULT_PATTERN = Pattern
.compile(DEFAULT_REGEX);
} }

View File

@ -2,12 +2,16 @@ package com.foxinmy.weixin4j.xml;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -38,173 +42,37 @@ import com.foxinmy.weixin4j.util.StringUtil;
*/ */
public class ListsuffixResultDeserializer { public class ListsuffixResultDeserializer {
private final static Pattern SUFFIX_PATTERN = Pattern.compile("(_\\d)$");
private final static Pattern TWO_SUFFIX_PATTERN = Pattern
.compile("_\\d{1,}_\\d{1,}$");
/** /**
* 对包含$n节点的xml序列化 * 对包含$n节点的xml序列化
* *
* @param content * @param content
* xml内容 * xml内容
* @param clazz * @param clazz
* @param listPropertyName
* 转换为list的属性名称
* @return * @return
*/ */
public static <T> T deserialize(String content, Class<T> clazz, public static <T> T deserialize(String content, Class<T> clazz) {
String listPropertyName) {
T t = XmlStream.fromXML(content, clazz); T t = XmlStream.fromXML(content, clazz);
Class<?> wrapperClazz = ReflectionUtil.getFieldGenericType(t, Map<Field, String[]> listsuffixFields = getListsuffixFields(clazz);
listPropertyName); if (!listsuffixFields.isEmpty()) {
ListWrapper<?> listWrapper = deserializeToListWrapper(content, for (Field field : listsuffixFields.keySet()) {
wrapperClazz); Type type = field.getGenericType();
if (listWrapper != null) { Class<?> wrapperClazz = null;
ReflectionUtil.invokeSetterMethod(t, listPropertyName, if (type instanceof ParameterizedType) {
listWrapper.getItems(), List.class); wrapperClazz = (Class<?>) ((ParameterizedType) type)
} .getActualTypeArguments()[0];
return t;
}
/**
* 对同时包含$n和$n_$m的xml序列化 refund_id_$n coupon_refund_id_$n_$m V3退款查询接口
*
* @param content
* xml内容
* @param clazz
* @param mainlistPropertyName
* $n结尾转换为list的属性名称
* @param subListPropertyName
* $n_$m结尾转换为list的熟悉名称
* @return
*/
public static <T> T deserializeHasTwoSuffix(String content, Class<T> clazz,
String mainlistPropertyName, String subListPropertyName) {
T t = XmlStream.fromXML(content, clazz);
Class<?> wrapperClazz = ReflectionUtil.getFieldGenericType(t,
mainlistPropertyName);
XMLStreamReader xr = null;
try {
xr = XMLInputFactory.newInstance().createXMLStreamReader(
new StringReader(content));
Matcher matcher = null;
Map<String, Map<String, String>> mainMap = new HashMap<String, Map<String, String>>();
Map<String, StringBuilder> subMap = new HashMap<String, StringBuilder>();
while (true) {
int event = xr.next();
if (event == XMLStreamConstants.END_DOCUMENT) {
break;
} else if (event == XMLStreamConstants.START_ELEMENT) {
String name = xr.getLocalName();
if ((matcher = SUFFIX_PATTERN.matcher(name)).find()) {
while (true) {
event = xr.next();
if (event == XMLStreamConstants.START_ELEMENT) {
name = xr.getLocalName();
} else if (event == XMLStreamConstants.END_ELEMENT) {
break;
} else if (event == XMLStreamConstants.CHARACTERS) {
String key = matcher.group();
if ((matcher = TWO_SUFFIX_PATTERN.matcher(name))
.find()) {
key = matcher.group().replaceFirst(
SUFFIX_PATTERN.pattern(), "");
StringBuilder sb = null;
if ((sb = subMap.get(key)) == null) {
sb = new StringBuilder();
subMap.put(key, sb);
}
String reverserName = new StringBuffer(
new StringBuilder(name)
.reverse()
.toString()
.replaceFirst("^(\\d_)", ""))
.reverse().toString();
sb.append("<").append(reverserName)
.append(">");
sb.append(xr.getText());
sb.append("</").append(reverserName)
.append(">");
} else { } else {
Map<String, String> innerMap = null; continue;
if ((innerMap = mainMap.get(key)) == null) {
innerMap = new HashMap<String, String>();
mainMap.put(key, innerMap);
} }
innerMap.put(name.replace(key, ""), ListWrapper<?> listWrapper = deserializeToListWrapper(content,
xr.getText()); wrapperClazz, listsuffixFields.get(field));
} if (listWrapper != null) {
}
}
}
}
}
if (!mainMap.isEmpty()) {
String itemName = StringUtil.uncapitalize(wrapperClazz
.getSimpleName());
XmlRootElement rootElement = wrapperClazz
.getAnnotation(XmlRootElement.class);
if (rootElement != null
&& StringUtil.isNotBlank(rootElement.name())) {
try { try {
if (!rootElement.name().equals( field.setAccessible(true);
XmlRootElement.class.getMethod("name") field.set(t, listWrapper.getItems());
.getDefaultValue().toString())) {
itemName = rootElement.name();
}
} catch (Exception e) { } catch (Exception e) {
; ;
} }
} }
List<Object> mainList = new ArrayList<Object>();
StringBuilder xmlBuilder = new StringBuilder();
for (Iterator<Entry<String, Map<String, String>>> refundIt = mainMap
.entrySet().iterator(); refundIt.hasNext();) {
xmlBuilder.delete(0, xmlBuilder.length());
xmlBuilder.append("<").append(itemName).append(">");
Entry<String, Map<String, String>> mainEntry = refundIt
.next();
for (Iterator<Entry<String, String>> mainInnerIt = mainEntry
.getValue().entrySet().iterator(); mainInnerIt
.hasNext();) {
Entry<String, String> entry = mainInnerIt.next();
xmlBuilder.append("<").append(entry.getKey())
.append(">");
xmlBuilder.append(entry.getValue());
xmlBuilder.append("</").append(entry.getKey())
.append(">");
}
xmlBuilder.append("</").append(itemName).append(">");
Object main = XmlStream.fromXML(xmlBuilder.toString(),
wrapperClazz);
StringBuilder subXml = subMap.get(mainEntry.getKey());
if (subXml != null) {
ListWrapper<?> listWrapper = deserializeToListWrapper(
String.format("<xml>%s</xml>",
subXml.toString()),
ReflectionUtil.getFieldGenericType(main,
subListPropertyName));
if (listWrapper != null) {
ReflectionUtil.invokeSetterMethod(main,
subListPropertyName,
listWrapper.getItems(), List.class);
}
}
mainList.add(main);
}
ReflectionUtil.invokeSetterMethod(t, mainlistPropertyName,
mainList, List.class);
}
} catch (XMLStreamException e) {
throw new IllegalArgumentException(e);
} finally {
try {
if (xr != null) {
xr.close();
}
} catch (XMLStreamException e) {
;
} }
} }
return t; return t;
@ -212,12 +80,16 @@ public class ListsuffixResultDeserializer {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> ListWrapper<T> deserializeToListWrapper(String content, public static <T> ListWrapper<T> deserializeToListWrapper(String content,
Class<T> clazz) { Class<T> clazz, String... matchPattern) {
XMLStreamReader xr = null; XMLStreamReader xr = null;
XMLStreamWriter xw = null; XMLStreamWriter xw = null;
try { try {
xr = XMLInputFactory.newInstance().createXMLStreamReader( xr = XMLInputFactory.newInstance().createXMLStreamReader(
new StringReader(content)); new StringReader(content));
List<Pattern> patterns = new ArrayList<Pattern>();
for (String pattern : matchPattern) {
patterns.add(Pattern.compile(pattern));
}
Matcher matcher = null; Matcher matcher = null;
Map<String, Map<String, String>> outMap = new HashMap<String, Map<String, String>>(); Map<String, Map<String, String>> outMap = new HashMap<String, Map<String, String>>();
while (true) { while (true) {
@ -226,7 +98,8 @@ public class ListsuffixResultDeserializer {
break; break;
} else if (event == XMLStreamConstants.START_ELEMENT) { } else if (event == XMLStreamConstants.START_ELEMENT) {
String name = xr.getLocalName(); String name = xr.getLocalName();
if ((matcher = SUFFIX_PATTERN.matcher(name)).find()) { for (Pattern pattern : patterns) {
if ((matcher = pattern.matcher(name)).find()) {
while (true) { while (true) {
event = xr.next(); event = xr.next();
if (event == XMLStreamConstants.START_ELEMENT) { if (event == XMLStreamConstants.START_ELEMENT) {
@ -235,6 +108,13 @@ public class ListsuffixResultDeserializer {
break; break;
} else if (event == XMLStreamConstants.CHARACTERS) { } else if (event == XMLStreamConstants.CHARACTERS) {
String key = matcher.group(); String key = matcher.group();
if (!pattern.pattern().equals(
ListsuffixResult.DEFAULT_REGEX)) {
matcher = ListsuffixResult.DEFAULT_PATTERN
.matcher(name);
matcher.find();
key = matcher.group();
}
Map<String, String> innerMap = null; Map<String, String> innerMap = null;
if ((innerMap = outMap.get(key)) == null) { if ((innerMap = outMap.get(key)) == null) {
innerMap = new HashMap<String, String>(); innerMap = new HashMap<String, String>();
@ -244,6 +124,8 @@ public class ListsuffixResultDeserializer {
xr.getText()); xr.getText());
} }
} }
break;
}
} }
} }
} }
@ -308,4 +190,17 @@ public class ListsuffixResultDeserializer {
} }
} }
} }
public static Map<Field, String[]> getListsuffixFields(Class<?> clazz) {
Map<Field, String[]> listsuffixFields = new HashMap<Field, String[]>();
Set<Field> allFields = ReflectionUtil.getAllField(clazz);
ListsuffixResult listsuffixResult = null;
for (Field field : allFields) {
listsuffixResult = field.getAnnotation(ListsuffixResult.class);
if (listsuffixResult != null) {
listsuffixFields.put(field, listsuffixResult.value());
}
}
return listsuffixFields;
}
} }

View File

@ -12,13 +12,12 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter; import javax.xml.stream.XMLStreamWriter;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.NameFilter; import com.alibaba.fastjson.serializer.NameFilter;
import com.alibaba.fastjson.serializer.PropertyFilter;
import com.foxinmy.weixin4j.model.Consts; import com.foxinmy.weixin4j.model.Consts;
import com.foxinmy.weixin4j.util.ReflectionUtil; import com.foxinmy.weixin4j.util.StringUtil;
/** /**
* 后缀为_$n xml节点序列化 * 后缀为_$n xml节点序列化
@ -31,8 +30,6 @@ import com.foxinmy.weixin4j.util.ReflectionUtil;
*/ */
public class ListsuffixResultSerializer { public class ListsuffixResultSerializer {
private static final String LISTSUFFIX_RESULT_NAME = "$listsuffix_result$";
/** /**
* 序列化为json * 序列化为json
* *
@ -40,31 +37,31 @@ public class ListsuffixResultSerializer {
* @return json * @return json
*/ */
public static JSONObject serializeToJSON(Object object) { public static JSONObject serializeToJSON(Object object) {
final JSONObject listsuffix = new JSONObject(); JSONObject result = (JSONObject) JSON.toJSON(object);
String preJson = JSON.toJSONString(object, new PropertyFilter() { Map<Field, String[]> listsuffixFields = ListsuffixResultDeserializer
@Override .getListsuffixFields(object.getClass());
public boolean apply(Object source, String name, Object value) { if (!listsuffixFields.isEmpty()) {
if (name.equalsIgnoreCase(LISTSUFFIX_RESULT_NAME)) { JSONField jsonField = null;
listsuffix.put(LISTSUFFIX_RESULT_NAME, JSON.toJSON(value)); Object value = null;
return false; for (Field field : listsuffixFields.keySet()) {
jsonField = field.getAnnotation(JSONField.class);
if (jsonField != null
&& StringUtil.isNotBlank(jsonField.name())) {
result.remove(jsonField.name());
} else {
result.remove(field.getName());
} }
Field field = ReflectionUtil.getAccessibleField(source, name);
if (field != null
&& field.getAnnotation(ListsuffixResult.class) != null) {
listsuffix.put(LISTSUFFIX_RESULT_NAME, JSON.toJSON(value));
return false;
}
return true;
}
});
JSONObject result = JSON.parseObject(preJson);
try { try {
Map<String, String> listMap = listsuffixConvertMap(listsuffix field.setAccessible(true);
.getJSONArray(LISTSUFFIX_RESULT_NAME)); value = field.get(object);
result.putAll(listMap); } catch (Exception e) {
} catch (JSONException e) {
;// ;//
} }
if (value != null && value instanceof List) {
result.putAll(listsuffixConvertMap((List<?>) value));
}
}
}
return result; return result;
} }
@ -115,6 +112,9 @@ public class ListsuffixResultSerializer {
xw.writeStartDocument(Consts.UTF_8.name(), "1.0"); xw.writeStartDocument(Consts.UTF_8.name(), "1.0");
xw.writeStartElement("xml"); xw.writeStartElement("xml");
for (String key : obj.keySet()) { for (String key : obj.keySet()) {
if (StringUtil.isBlank(obj.getString(key))) {
continue;
}
xw.writeStartElement(key); xw.writeStartElement(key);
xw.writeCData(obj.getString(key)); xw.writeCData(obj.getString(key));
xw.writeEndElement(); xw.writeEndElement();

View File

@ -443,7 +443,7 @@ public class Pay2Api extends PayApi {
map.put("sign", sign.toLowerCase()); map.put("sign", sign.toLowerCase());
WeixinResponse response = weixinClient.get(refundquery_uri, map); WeixinResponse response = weixinClient.get(refundquery_uri, map);
return ListsuffixResultDeserializer.deserialize(response.getAsString(), return ListsuffixResultDeserializer.deserialize(response.getAsString(),
RefundRecord.class, "refundList"); RefundRecord.class);
} }
@Override @Override

View File

@ -81,7 +81,7 @@ public class Pay3Api extends PayApi {
String orderquery_uri = getRequestUri("orderquery_v3_uri"); String orderquery_uri = getRequestUri("orderquery_v3_uri");
WeixinResponse response = weixinClient.post(orderquery_uri, param); WeixinResponse response = weixinClient.post(orderquery_uri, param);
return ListsuffixResultDeserializer.deserialize(response.getAsString(), return ListsuffixResultDeserializer.deserialize(response.getAsString(),
Order.class, "couponList"); Order.class);
} }
/** /**
@ -394,9 +394,8 @@ public class Pay3Api extends PayApi {
map.put("sign", sign); map.put("sign", sign);
String param = XmlStream.map2xml(map); String param = XmlStream.map2xml(map);
WeixinResponse response = weixinClient.post(refundquery_uri, param); WeixinResponse response = weixinClient.post(refundquery_uri, param);
return ListsuffixResultDeserializer.deserializeHasTwoSuffix( return ListsuffixResultDeserializer.deserialize(
response.getAsString(), RefundRecord.class, "refundList", response.getAsString(), RefundRecord.class);
"couponList");
} }
/** /**

View File

@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.xml.ListsuffixResult; import com.foxinmy.weixin4j.xml.ListsuffixResult;
@ -48,8 +47,6 @@ public class RefundRecord extends ApiResult {
* 退款详情 * 退款详情
*/ */
@ListsuffixResult @ListsuffixResult
@XmlTransient
@JSONField(deserialize = false)
private List<RefundDetail> refundList; private List<RefundDetail> refundList;
protected RefundRecord() { protected RefundRecord() {

View File

@ -7,7 +7,6 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.mp.payment.coupon.CouponInfo; import com.foxinmy.weixin4j.mp.payment.coupon.CouponInfo;
@ -88,8 +87,6 @@ public class Order extends ApiResult {
* 代金券信息 验证签名有点麻烦 * 代金券信息 验证签名有点麻烦
*/ */
@ListsuffixResult @ListsuffixResult
@XmlTransient
@JSONField(deserialize = false)
private List<CouponInfo> couponList; private List<CouponInfo> couponList;
/** /**
* 现金支付金额 * 现金支付金额

View File

@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.mp.payment.coupon.CouponInfo; import com.foxinmy.weixin4j.mp.payment.coupon.CouponInfo;
@ -131,8 +130,6 @@ public class RefundDetail extends ApiResult {
* @see com.foxinmy.weixin4j.mp.payment.coupon.CouponInfo * @see com.foxinmy.weixin4j.mp.payment.coupon.CouponInfo
*/ */
@ListsuffixResult @ListsuffixResult
@XmlTransient
@JSONField(deserialize = false)
private List<CouponInfo> couponList; private List<CouponInfo> couponList;
protected RefundDetail() { protected RefundDetail() {

View File

@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.mp.type.CurrencyType; import com.foxinmy.weixin4j.mp.type.CurrencyType;
@ -89,9 +88,7 @@ public class RefundRecord extends ApiResult {
* *
* @see com.foxinmy.weixin4j.mp.payment.v3.RefundDetail * @see com.foxinmy.weixin4j.mp.payment.v3.RefundDetail
*/ */
@ListsuffixResult @ListsuffixResult({ "out_refund_no(_\\d)$", "^refund_.*(_\\d)$" })
@XmlTransient
@JSONField(deserialize = false)
private List<RefundDetail> refundList; private List<RefundDetail> refundList;
protected RefundRecord() { protected RefundRecord() {

View File

@ -6,11 +6,9 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.foxinmy.weixin4j.model.Token; import com.foxinmy.weixin4j.model.Token;
import com.foxinmy.weixin4j.mp.payment.PayUtil;
import com.foxinmy.weixin4j.mp.payment.v2.RefundRecord; import com.foxinmy.weixin4j.mp.payment.v2.RefundRecord;
import com.foxinmy.weixin4j.mp.payment.v3.Order; import com.foxinmy.weixin4j.mp.payment.v3.Order;
import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer; import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
import com.foxinmy.weixin4j.xml.ListsuffixResultSerializer;
import com.foxinmy.weixin4j.xml.XmlStream; import com.foxinmy.weixin4j.xml.XmlStream;
public class XmlstreamTest { public class XmlstreamTest {
@ -63,7 +61,7 @@ public class XmlstreamTest {
} }
System.err.println(ListsuffixResultDeserializer.deserialize( System.err.println(ListsuffixResultDeserializer.deserialize(
sb.toString(), Order.class, "couponList")); sb.toString(), Order.class));
} }
public static RefundRecord xml2refundRecordV2() throws Exception { public static RefundRecord xml2refundRecordV2() throws Exception {
@ -80,7 +78,7 @@ public class XmlstreamTest {
} }
return ListsuffixResultDeserializer.deserialize(sb.toString(), return ListsuffixResultDeserializer.deserialize(sb.toString(),
RefundRecord.class, "refundList"); RefundRecord.class);
} }
public static void xml2refundRecordV3() throws Exception { public static void xml2refundRecordV3() throws Exception {
@ -96,26 +94,27 @@ public class XmlstreamTest {
} catch (Exception e) { } catch (Exception e) {
} }
System.err.println(ListsuffixResultDeserializer System.err.println(ListsuffixResultDeserializer.deserialize(
.deserializeHasTwoSuffix(sb.toString(), sb.toString(),
com.foxinmy.weixin4j.mp.payment.v3.RefundRecord.class, com.foxinmy.weixin4j.mp.payment.v3.RefundRecord.class));
"refundList", "couponList"));
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// map2xml(); // map2xml();
// xml2map(); // xml2map();
// xml2order(); // xml2order();
// xml2refundRecordV2(); // System.err.println(xml2refundRecordV2());
xml2refundRecordV3(); xml2refundRecordV3();
// object2xmlWithoutRootElement(); // object2xmlWithoutRootElement();
RefundRecord refundRecord = xml2refundRecordV2();
/*RefundRecord refundRecord = xml2refundRecordV2();
System.err.println(refundRecord); System.err.println(refundRecord);
String sign = refundRecord.getSign(); String sign = refundRecord.getSign();
refundRecord.setSign(null); refundRecord.setSign(null);
String validSign = PayUtil.paysignMd5(refundRecord, "paysignkey"); String validSign = PayUtil.paysignMd5(refundRecord, "paysignkey");
System.err.println("sign=" + sign + ",validSign=" + validSign); System.err.println("sign=" + sign + ",validSign=" + validSign);
System.err.println(ListsuffixResultSerializer System.err.println(ListsuffixResultSerializer
.serializeToXML(refundRecord)); .serializeToXML(refundRecord));*/
} }
} }