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