对返回结果中以$n结尾的节点的序列化做了优化
This commit is contained in:
parent
5ffc7f2a98
commit
692a2b8129
@ -3,8 +3,11 @@ package com.foxinmy.weixin4j.util;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @title 反射工具类
|
||||
@ -214,4 +217,20 @@ public class ReflectionUtil {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,9 +4,23 @@ import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
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)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
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);
|
||||
}
|
||||
|
||||
@ -2,12 +2,16 @@ package com.foxinmy.weixin4j.xml;
|
||||
|
||||
import java.io.StringReader;
|
||||
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.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -38,173 +42,37 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
||||
*/
|
||||
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序列化
|
||||
*
|
||||
* @param content
|
||||
* xml内容
|
||||
* @param clazz
|
||||
* @param listPropertyName
|
||||
* 转换为list的属性名称
|
||||
* @return
|
||||
*/
|
||||
public static <T> T deserialize(String content, Class<T> clazz,
|
||||
String listPropertyName) {
|
||||
public static <T> T deserialize(String content, Class<T> clazz) {
|
||||
T t = XmlStream.fromXML(content, clazz);
|
||||
Class<?> wrapperClazz = ReflectionUtil.getFieldGenericType(t,
|
||||
listPropertyName);
|
||||
ListWrapper<?> listWrapper = deserializeToListWrapper(content,
|
||||
wrapperClazz);
|
||||
if (listWrapper != null) {
|
||||
ReflectionUtil.invokeSetterMethod(t, listPropertyName,
|
||||
listWrapper.getItems(), List.class);
|
||||
}
|
||||
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 {
|
||||
Map<String, String> innerMap = null;
|
||||
if ((innerMap = mainMap.get(key)) == null) {
|
||||
innerMap = new HashMap<String, String>();
|
||||
mainMap.put(key, innerMap);
|
||||
}
|
||||
innerMap.put(name.replace(key, ""),
|
||||
xr.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<Field, String[]> listsuffixFields = getListsuffixFields(clazz);
|
||||
if (!listsuffixFields.isEmpty()) {
|
||||
for (Field field : listsuffixFields.keySet()) {
|
||||
Type type = field.getGenericType();
|
||||
Class<?> wrapperClazz = null;
|
||||
if (type instanceof ParameterizedType) {
|
||||
wrapperClazz = (Class<?>) ((ParameterizedType) type)
|
||||
.getActualTypeArguments()[0];
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!mainMap.isEmpty()) {
|
||||
String itemName = StringUtil.uncapitalize(wrapperClazz
|
||||
.getSimpleName());
|
||||
XmlRootElement rootElement = wrapperClazz
|
||||
.getAnnotation(XmlRootElement.class);
|
||||
if (rootElement != null
|
||||
&& StringUtil.isNotBlank(rootElement.name())) {
|
||||
ListWrapper<?> listWrapper = deserializeToListWrapper(content,
|
||||
wrapperClazz, listsuffixFields.get(field));
|
||||
if (listWrapper != null) {
|
||||
try {
|
||||
if (!rootElement.name().equals(
|
||||
XmlRootElement.class.getMethod("name")
|
||||
.getDefaultValue().toString())) {
|
||||
itemName = rootElement.name();
|
||||
}
|
||||
field.setAccessible(true);
|
||||
field.set(t, listWrapper.getItems());
|
||||
} 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;
|
||||
@ -212,12 +80,16 @@ public class ListsuffixResultDeserializer {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> ListWrapper<T> deserializeToListWrapper(String content,
|
||||
Class<T> clazz) {
|
||||
Class<T> clazz, String... matchPattern) {
|
||||
XMLStreamReader xr = null;
|
||||
XMLStreamWriter xw = null;
|
||||
try {
|
||||
xr = XMLInputFactory.newInstance().createXMLStreamReader(
|
||||
new StringReader(content));
|
||||
List<Pattern> patterns = new ArrayList<Pattern>();
|
||||
for (String pattern : matchPattern) {
|
||||
patterns.add(Pattern.compile(pattern));
|
||||
}
|
||||
Matcher matcher = null;
|
||||
Map<String, Map<String, String>> outMap = new HashMap<String, Map<String, String>>();
|
||||
while (true) {
|
||||
@ -226,23 +98,33 @@ public class ListsuffixResultDeserializer {
|
||||
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();
|
||||
Map<String, String> innerMap = null;
|
||||
if ((innerMap = outMap.get(key)) == null) {
|
||||
innerMap = new HashMap<String, String>();
|
||||
outMap.put(key, innerMap);
|
||||
for (Pattern pattern : patterns) {
|
||||
if ((matcher = 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 (!pattern.pattern().equals(
|
||||
ListsuffixResult.DEFAULT_REGEX)) {
|
||||
matcher = ListsuffixResult.DEFAULT_PATTERN
|
||||
.matcher(name);
|
||||
matcher.find();
|
||||
key = matcher.group();
|
||||
}
|
||||
Map<String, String> innerMap = null;
|
||||
if ((innerMap = outMap.get(key)) == null) {
|
||||
innerMap = new HashMap<String, String>();
|
||||
outMap.put(key, innerMap);
|
||||
}
|
||||
innerMap.put(name.replace(key, ""),
|
||||
xr.getText());
|
||||
}
|
||||
innerMap.put(name.replace(key, ""),
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,13 +12,12 @@ import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.serializer.NameFilter;
|
||||
import com.alibaba.fastjson.serializer.PropertyFilter;
|
||||
import com.foxinmy.weixin4j.model.Consts;
|
||||
import com.foxinmy.weixin4j.util.ReflectionUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 对 后缀为_$n 的 xml节点序列化
|
||||
@ -31,8 +30,6 @@ import com.foxinmy.weixin4j.util.ReflectionUtil;
|
||||
*/
|
||||
public class ListsuffixResultSerializer {
|
||||
|
||||
private static final String LISTSUFFIX_RESULT_NAME = "$listsuffix_result$";
|
||||
|
||||
/**
|
||||
* 序列化为json
|
||||
*
|
||||
@ -40,30 +37,30 @@ public class ListsuffixResultSerializer {
|
||||
* @return json
|
||||
*/
|
||||
public static JSONObject serializeToJSON(Object object) {
|
||||
final JSONObject listsuffix = new JSONObject();
|
||||
String preJson = JSON.toJSONString(object, new PropertyFilter() {
|
||||
@Override
|
||||
public boolean apply(Object source, String name, Object value) {
|
||||
if (name.equalsIgnoreCase(LISTSUFFIX_RESULT_NAME)) {
|
||||
listsuffix.put(LISTSUFFIX_RESULT_NAME, JSON.toJSON(value));
|
||||
return false;
|
||||
JSONObject result = (JSONObject) JSON.toJSON(object);
|
||||
Map<Field, String[]> listsuffixFields = ListsuffixResultDeserializer
|
||||
.getListsuffixFields(object.getClass());
|
||||
if (!listsuffixFields.isEmpty()) {
|
||||
JSONField jsonField = null;
|
||||
Object value = null;
|
||||
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;
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
value = field.get(object);
|
||||
} catch (Exception e) {
|
||||
;//
|
||||
}
|
||||
if (value != null && value instanceof List) {
|
||||
result.putAll(listsuffixConvertMap((List<?>) value));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
JSONObject result = JSON.parseObject(preJson);
|
||||
try {
|
||||
Map<String, String> listMap = listsuffixConvertMap(listsuffix
|
||||
.getJSONArray(LISTSUFFIX_RESULT_NAME));
|
||||
result.putAll(listMap);
|
||||
} catch (JSONException e) {
|
||||
;//
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -115,6 +112,9 @@ public class ListsuffixResultSerializer {
|
||||
xw.writeStartDocument(Consts.UTF_8.name(), "1.0");
|
||||
xw.writeStartElement("xml");
|
||||
for (String key : obj.keySet()) {
|
||||
if (StringUtil.isBlank(obj.getString(key))) {
|
||||
continue;
|
||||
}
|
||||
xw.writeStartElement(key);
|
||||
xw.writeCData(obj.getString(key));
|
||||
xw.writeEndElement();
|
||||
|
||||
@ -443,7 +443,7 @@ public class Pay2Api extends PayApi {
|
||||
map.put("sign", sign.toLowerCase());
|
||||
WeixinResponse response = weixinClient.get(refundquery_uri, map);
|
||||
return ListsuffixResultDeserializer.deserialize(response.getAsString(),
|
||||
RefundRecord.class, "refundList");
|
||||
RefundRecord.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -81,7 +81,7 @@ public class Pay3Api extends PayApi {
|
||||
String orderquery_uri = getRequestUri("orderquery_v3_uri");
|
||||
WeixinResponse response = weixinClient.post(orderquery_uri, param);
|
||||
return ListsuffixResultDeserializer.deserialize(response.getAsString(),
|
||||
Order.class, "couponList");
|
||||
Order.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -394,9 +394,8 @@ public class Pay3Api extends PayApi {
|
||||
map.put("sign", sign);
|
||||
String param = XmlStream.map2xml(map);
|
||||
WeixinResponse response = weixinClient.post(refundquery_uri, param);
|
||||
return ListsuffixResultDeserializer.deserializeHasTwoSuffix(
|
||||
response.getAsString(), RefundRecord.class, "refundList",
|
||||
"couponList");
|
||||
return ListsuffixResultDeserializer.deserialize(
|
||||
response.getAsString(), RefundRecord.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.xml.ListsuffixResult;
|
||||
@ -48,8 +47,6 @@ public class RefundRecord extends ApiResult {
|
||||
* 退款详情
|
||||
*/
|
||||
@ListsuffixResult
|
||||
@XmlTransient
|
||||
@JSONField(deserialize = false)
|
||||
private List<RefundDetail> refundList;
|
||||
|
||||
protected RefundRecord() {
|
||||
|
||||
@ -7,7 +7,6 @@ import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.payment.coupon.CouponInfo;
|
||||
@ -88,8 +87,6 @@ public class Order extends ApiResult {
|
||||
* 代金券信息 验证签名有点麻烦
|
||||
*/
|
||||
@ListsuffixResult
|
||||
@XmlTransient
|
||||
@JSONField(deserialize = false)
|
||||
private List<CouponInfo> couponList;
|
||||
/**
|
||||
* 现金支付金额
|
||||
|
||||
@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
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
|
||||
*/
|
||||
@ListsuffixResult
|
||||
@XmlTransient
|
||||
@JSONField(deserialize = false)
|
||||
private List<CouponInfo> couponList;
|
||||
|
||||
protected RefundDetail() {
|
||||
|
||||
@ -6,7 +6,6 @@ import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.mp.type.CurrencyType;
|
||||
@ -89,9 +88,7 @@ public class RefundRecord extends ApiResult {
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.mp.payment.v3.RefundDetail
|
||||
*/
|
||||
@ListsuffixResult
|
||||
@XmlTransient
|
||||
@JSONField(deserialize = false)
|
||||
@ListsuffixResult({ "out_refund_no(_\\d)$", "^refund_.*(_\\d)$" })
|
||||
private List<RefundDetail> refundList;
|
||||
|
||||
protected RefundRecord() {
|
||||
|
||||
@ -6,11 +6,9 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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.v3.Order;
|
||||
import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
|
||||
import com.foxinmy.weixin4j.xml.ListsuffixResultSerializer;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
public class XmlstreamTest {
|
||||
@ -63,7 +61,7 @@ public class XmlstreamTest {
|
||||
|
||||
}
|
||||
System.err.println(ListsuffixResultDeserializer.deserialize(
|
||||
sb.toString(), Order.class, "couponList"));
|
||||
sb.toString(), Order.class));
|
||||
}
|
||||
|
||||
public static RefundRecord xml2refundRecordV2() throws Exception {
|
||||
@ -80,7 +78,7 @@ public class XmlstreamTest {
|
||||
|
||||
}
|
||||
return ListsuffixResultDeserializer.deserialize(sb.toString(),
|
||||
RefundRecord.class, "refundList");
|
||||
RefundRecord.class);
|
||||
}
|
||||
|
||||
public static void xml2refundRecordV3() throws Exception {
|
||||
@ -96,26 +94,27 @@ public class XmlstreamTest {
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
System.err.println(ListsuffixResultDeserializer
|
||||
.deserializeHasTwoSuffix(sb.toString(),
|
||||
com.foxinmy.weixin4j.mp.payment.v3.RefundRecord.class,
|
||||
"refundList", "couponList"));
|
||||
System.err.println(ListsuffixResultDeserializer.deserialize(
|
||||
sb.toString(),
|
||||
com.foxinmy.weixin4j.mp.payment.v3.RefundRecord.class));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// map2xml();
|
||||
// xml2map();
|
||||
// xml2order();
|
||||
// xml2refundRecordV2();
|
||||
// System.err.println(xml2refundRecordV2());
|
||||
xml2refundRecordV3();
|
||||
// object2xmlWithoutRootElement();
|
||||
RefundRecord refundRecord = xml2refundRecordV2();
|
||||
|
||||
/*RefundRecord refundRecord = xml2refundRecordV2();
|
||||
System.err.println(refundRecord);
|
||||
String sign = refundRecord.getSign();
|
||||
refundRecord.setSign(null);
|
||||
String validSign = PayUtil.paysignMd5(refundRecord, "paysignkey");
|
||||
System.err.println("sign=" + sign + ",validSign=" + validSign);
|
||||
System.err.println(ListsuffixResultSerializer
|
||||
.serializeToXML(refundRecord));
|
||||
.serializeToXML(refundRecord));*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user