
net.arccode.wechat.pay.api.common.parser.xml.XmlConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wechat-pay-sdk Show documentation
Show all versions of wechat-pay-sdk Show documentation
wechat pay SDK, out of the box.
The newest version!
package net.arccode.wechat.pay.api.common.parser.xml;
import net.arccode.wechat.pay.api.common.constant.WXPayConstants;
import net.arccode.wechat.pay.api.common.exception.WXPayApiException;
import net.arccode.wechat.pay.api.common.parser.Converter;
import net.arccode.wechat.pay.api.common.util.Converters;
import net.arccode.wechat.pay.api.protocol.base.WXPayResponse;
import net.arccode.wechat.pay.api.common.parser.Reader;
import net.arccode.wechat.pay.api.common.util.XmlUtils;
import org.w3c.dom.Element;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* xml格式转换
*
* @author http://arccode.net
* @since 2015-11-05
*/
public class XmlConverter implements Converter {
@Override
public T toResponse(String resp, Class clazz) throws WXPayApiException {
Element root = XmlUtils.getRootElementFromString(resp);
return getModelFromXML(root, clazz);
}
private T getModelFromXML(final Element element, Class clazz) throws WXPayApiException {
if (element == null)
return null;
return Converters.convert(clazz, new Reader() {
public boolean hasReturnField(Object name) {
Element childE = XmlUtils.getChildElement(element, (String) name);
return childE != null;
}
public Object getPrimitiveObject(Object name) {
return XmlUtils.getElementValue(element, (String) name);
}
public Object getObject(Object name, Class> type) throws WXPayApiException {
Element childE = XmlUtils.getChildElement(element, (String) name);
if (childE != null) {
return getModelFromXML(childE, type);
} else {
return null;
}
}
public List> getListObjects(Object listName, Object itemName, Class> subType)
throws WXPayApiException {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy