mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-04 04:37:46 +08:00
🎨 优化部分代码
This commit is contained in:
parent
7a4336d28c
commit
211f4c7f74
@ -1,17 +1,7 @@
|
|||||||
package com.github.binarywang.wxpay.converter;
|
package com.github.binarywang.wxpay.converter;
|
||||||
|
|
||||||
import java.beans.PropertyDescriptor;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyCoupon;
|
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyCoupon;
|
||||||
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
@ -22,6 +12,14 @@ import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
|
|||||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||||
import com.thoughtworks.xstream.mapper.Mapper;
|
import com.thoughtworks.xstream.mapper.Mapper;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.beans.PropertyDescriptor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Wxpay order notify result converter.
|
* The type Wxpay order notify result converter.
|
||||||
@ -63,7 +61,7 @@ public class WxPayOrderNotifyResultConverter extends AbstractReflectionConverter
|
|||||||
writer.setValue(coupon.getCouponType());
|
writer.setValue(coupon.getCouponType());
|
||||||
writer.endNode();
|
writer.endNode();
|
||||||
writer.startNode("coupon_fee_" + i);
|
writer.startNode("coupon_fee_" + i);
|
||||||
writer.setValue(coupon.getCouponFee() + "");
|
writer.setValue(String.valueOf(coupon.getCouponFee()));
|
||||||
writer.endNode();
|
writer.endNode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,8 +110,8 @@ public class WxPayOrderNotifyResultConverter extends AbstractReflectionConverter
|
|||||||
Object val = context.convertAnother(obj, field.getType());
|
Object val = context.convertAnother(obj, field.getType());
|
||||||
try {
|
try {
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
//这里加一个看似多余的(String)强转可解决高jdk版本下的编译报错问题,详情见讨论https://github.com/vaadin/framework/issues/10737
|
//这里加一个看似多余的(String)强转可解决高jdk版本下的编译报错问题,详情见讨论https://github.com/vaadin/framework/issues/10737
|
||||||
PropertyDescriptor pd = new PropertyDescriptor((String)field.getName(), obj.getClass());
|
PropertyDescriptor pd = new PropertyDescriptor(field.getName(), obj.getClass());
|
||||||
pd.getWriteMethod().invoke(obj, val);
|
pd.getWriteMethod().invoke(obj, val);
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
@ -121,14 +119,11 @@ public class WxPayOrderNotifyResultConverter extends AbstractReflectionConverter
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Field> getFieldMap(List<Field> fields) {
|
private Map<String, Field> getFieldMap(List<Field> fields) {
|
||||||
return Maps.uniqueIndex(fields, new Function<Field, String>() {
|
return Maps.uniqueIndex(fields, field -> {
|
||||||
@Override
|
if (field.isAnnotationPresent(XStreamAlias.class)) {
|
||||||
public String apply(Field field) {
|
return field.getAnnotation(XStreamAlias.class).value();
|
||||||
if (field.isAnnotationPresent(XStreamAlias.class)) {
|
|
||||||
return field.getAnnotation(XStreamAlias.class).value();
|
|
||||||
}
|
|
||||||
return field.getName();
|
|
||||||
}
|
}
|
||||||
|
return field.getName();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user