修改 map2xml 方法 传递参数中value为空时的bug
This commit is contained in:
parent
12fdf6065b
commit
94a9995b86
@ -57,8 +57,7 @@ public class WeixinPayAccount extends WeixinAccount {
|
||||
* @param mchId
|
||||
* 微信支付分配的商户号(必填)
|
||||
*/
|
||||
public WeixinPayAccount(String appId, String appSecret, String paySignKey,
|
||||
String mchId) {
|
||||
public WeixinPayAccount(String appId, String appSecret, String paySignKey, String mchId) {
|
||||
this(appId, appSecret, paySignKey, mchId, null, null, null, null);
|
||||
}
|
||||
|
||||
@ -66,31 +65,27 @@ public class WeixinPayAccount extends WeixinAccount {
|
||||
* 支付商户信息
|
||||
*
|
||||
* @param appId
|
||||
* 公众号唯一的身份ID
|
||||
* 公众号唯一的身份ID(必填)
|
||||
* @param appSecret
|
||||
* 调用接口的凭证
|
||||
* 调用接口的凭证(必填)
|
||||
* @param paySignKey
|
||||
* 支付密钥字符串(必填)
|
||||
* @param mchId
|
||||
* 微信支付分配的商户号(V3版本必填)
|
||||
* 微信支付分配的商户号(V3商户平台版必填)
|
||||
* @param subMchId
|
||||
* 微信支付分配的子商户号,受理模式下必填(V3商户平台版 非必须)
|
||||
* @param deviceInfo
|
||||
* 微信支付分配的设备号(V3商户平台版 非必须)
|
||||
* @param partnerId
|
||||
* 财付通的商户号(V2版本必填)
|
||||
* @param partnerKey
|
||||
* 财付通商户权限密钥Key(V2版本必填)
|
||||
* @param subMchId
|
||||
* 微信支付分配的子商户号,受理模式下必填(商户平台版)
|
||||
* @param deviceInfo
|
||||
* 微信支付分配的设备号(商户平台版)
|
||||
*/
|
||||
@JSONCreator
|
||||
public WeixinPayAccount(@JSONField(name = "id") String appId,
|
||||
@JSONField(name = "secret") String appSecret,
|
||||
@JSONField(name = "paySignKey") String paySignKey,
|
||||
@JSONField(name = "mchId") String mchId,
|
||||
@JSONField(name = "subMchId") String subMchId,
|
||||
@JSONField(name = "deviceInfo") String deviceInfo,
|
||||
@JSONField(name = "partnerId") String partnerId,
|
||||
@JSONField(name = "partnerKey") String partnerKey) {
|
||||
public WeixinPayAccount(@JSONField(name = "id") String appId, @JSONField(name = "secret") String appSecret,
|
||||
@JSONField(name = "paySignKey") String paySignKey, @JSONField(name = "mchId") String mchId,
|
||||
@JSONField(name = "subMchId") String subMchId, @JSONField(name = "deviceInfo") String deviceInfo,
|
||||
@JSONField(name = "partnerId") String partnerId, @JSONField(name = "partnerKey") String partnerKey) {
|
||||
super(appId, appSecret);
|
||||
this.paySignKey = paySignKey;
|
||||
this.mchId = mchId;
|
||||
@ -133,10 +128,8 @@ public class WeixinPayAccount extends WeixinAccount {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WeixinPayAccount [" + super.toString() + ", paySignKey="
|
||||
+ paySignKey + ", partnerId=" + partnerId + ", partnerKey="
|
||||
+ partnerKey + ", mchId=" + mchId + ", subMchId=" + subMchId
|
||||
+ ", deviceInfo=" + deviceInfo + ", version=" + getVersion()
|
||||
+ "]";
|
||||
return "WeixinPayAccount [" + super.toString() + ", paySignKey=" + paySignKey + ", partnerId=" + partnerId
|
||||
+ ", partnerKey=" + partnerKey + ", mchId=" + mchId + ", subMchId=" + subMchId + ", deviceInfo="
|
||||
+ deviceInfo + ", version=" + getVersion() + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,6 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBElement;
|
||||
@ -47,6 +46,7 @@ public final class XmlStream {
|
||||
private final static String XML_VERSION = "1.0";
|
||||
private final static Map<Class<?>, Unmarshaller> messageUnmarshaller;
|
||||
private final static Map<Class<?>, Marshaller> messageMarshaller;
|
||||
|
||||
static {
|
||||
messageUnmarshaller = new HashMap<Class<?>, Unmarshaller>();
|
||||
messageMarshaller = new HashMap<Class<?>, Marshaller>();
|
||||
@ -75,13 +75,10 @@ public final class XmlStream {
|
||||
}
|
||||
try {
|
||||
Source source = new StreamSource(content);
|
||||
XmlRootElement rootElement = clazz
|
||||
.getAnnotation(XmlRootElement.class);
|
||||
if (rootElement == null || rootElement.name().equals(
|
||||
XmlRootElement.class.getMethod("name")
|
||||
.getDefaultValue().toString())) {
|
||||
JAXBElement<T> jaxbElement = unmarshaller.unmarshal(source,
|
||||
clazz);
|
||||
XmlRootElement rootElement = clazz.getAnnotation(XmlRootElement.class);
|
||||
if (rootElement == null
|
||||
|| rootElement.name().equals(XmlRootElement.class.getMethod("name").getDefaultValue().toString())) {
|
||||
JAXBElement<T> jaxbElement = unmarshaller.unmarshal(source, clazz);
|
||||
return jaxbElement.getValue();
|
||||
} else {
|
||||
return (T) unmarshaller.unmarshal(source);
|
||||
@ -109,8 +106,7 @@ public final class XmlStream {
|
||||
* @return
|
||||
*/
|
||||
public static <T> T fromXML(String content, Class<T> clazz) {
|
||||
return fromXML(
|
||||
new ByteArrayInputStream(content.getBytes(Consts.UTF_8)), clazz);
|
||||
return fromXML(new ByteArrayInputStream(content.getBytes(Consts.UTF_8)), clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,13 +119,14 @@ public final class XmlStream {
|
||||
public static String map2xml(Map<String, String> map) {
|
||||
StringWriter sw = new StringWriter();
|
||||
try {
|
||||
XMLStreamWriter xw = XMLOutputFactory.newInstance()
|
||||
.createXMLStreamWriter(sw);
|
||||
XMLStreamWriter xw = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
|
||||
xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION);
|
||||
xw.writeStartElement(ROOT_ELEMENT_XML);
|
||||
for (Iterator<Entry<String, String>> it = map.entrySet().iterator(); it
|
||||
.hasNext();) {
|
||||
for (Iterator<Entry<String, String>> it = map.entrySet().iterator(); it.hasNext();) {
|
||||
Entry<String, String> entry = it.next();
|
||||
if (StringUtil.isBlank(entry.getValue())) {
|
||||
continue;
|
||||
}
|
||||
xw.writeStartElement(entry.getKey());
|
||||
xw.writeCData(entry.getValue());
|
||||
xw.writeEndElement();
|
||||
@ -149,17 +146,26 @@ public final class XmlStream {
|
||||
return sw.getBuffer().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* map2xml
|
||||
*
|
||||
* @param json
|
||||
* value无嵌套的json
|
||||
* @return xml内容
|
||||
*/
|
||||
public static String map2xml(JSONObject json) {
|
||||
StringWriter sw = new StringWriter();
|
||||
try {
|
||||
XMLStreamWriter xw = XMLOutputFactory.newInstance()
|
||||
.createXMLStreamWriter(sw);
|
||||
XMLStreamWriter xw = XMLOutputFactory.newInstance().createXMLStreamWriter(sw);
|
||||
xw.writeStartDocument(Consts.UTF_8.name(), XML_VERSION);
|
||||
xw.writeStartElement(ROOT_ELEMENT_XML);
|
||||
Set<String> keys = json.keySet();
|
||||
for (String key : keys) {
|
||||
xw.writeStartElement(key);
|
||||
xw.writeCData(json.getString(key));
|
||||
for (Iterator<Entry<String, Object>> it = json.entrySet().iterator(); it.hasNext();) {
|
||||
Entry<String, Object> entry = it.next();
|
||||
if (StringUtil.isBlank(json.getString(entry.getKey()))) {
|
||||
continue;
|
||||
}
|
||||
xw.writeStartElement(entry.getKey());
|
||||
xw.writeCData(json.getString(entry.getKey()));
|
||||
xw.writeEndElement();
|
||||
}
|
||||
xw.writeEndDocument();
|
||||
@ -188,8 +194,7 @@ public final class XmlStream {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
StringReader sr = new StringReader(content);
|
||||
try {
|
||||
XMLStreamReader xr = XMLInputFactory.newInstance()
|
||||
.createXMLStreamReader(sr);
|
||||
XMLStreamReader xr = XMLInputFactory.newInstance().createXMLStreamReader(sr);
|
||||
while (true) {
|
||||
int event = xr.next();
|
||||
if (event == XMLStreamConstants.END_DOCUMENT) {
|
||||
@ -254,14 +259,10 @@ public final class XmlStream {
|
||||
}
|
||||
}
|
||||
try {
|
||||
XmlRootElement rootElement = clazz
|
||||
.getAnnotation(XmlRootElement.class);
|
||||
XmlRootElement rootElement = clazz.getAnnotation(XmlRootElement.class);
|
||||
if (rootElement == null
|
||||
|| rootElement.name().equals(
|
||||
XmlRootElement.class.getMethod("name")
|
||||
.getDefaultValue().toString())) {
|
||||
marshaller.marshal(new JAXBElement<T>(new QName(
|
||||
ROOT_ELEMENT_XML), clazz, t), os);
|
||||
|| rootElement.name().equals(XmlRootElement.class.getMethod("name").getDefaultValue().toString())) {
|
||||
marshaller.marshal(new JAXBElement<T>(new QName(ROOT_ELEMENT_XML), clazz, t), os);
|
||||
} else {
|
||||
marshaller.marshal(t, os);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user