mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-09-20 02:29:44 +08:00
issue #71 替换掉JAXB,避免因OpenJDK造成无法deserialize xml的错误
This commit is contained in:
@@ -1,68 +1,73 @@
|
||||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>me.chanjar</groupId>
|
||||
<artifactId>weixin-java-parent</artifactId>
|
||||
<version>1.0.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>me.chanjar</groupId>
|
||||
<artifactId>weixin-java-parent</artifactId>
|
||||
<version>1.0.7-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-java-common</artifactId>
|
||||
<name>WeiXin Java Tools - Common</name>
|
||||
<description>微信公众号、企业号Java SDK Common</description>
|
||||
<artifactId>weixin-java-common</artifactId>
|
||||
<name>WeiXin Java Tools - Common</name>
|
||||
<description>微信公众号、企业号Java SDK Common</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.8.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.9.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
<version>3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>9.3.0.M0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>9.3.0.M0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
<version>1.4.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.8.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.9.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
<version>3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>9.3.0.M0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>9.3.0.M0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<suiteXmlFiles>
|
||||
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
|
||||
</suiteXmlFiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<suiteXmlFiles>
|
||||
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
|
||||
</suiteXmlFiles>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
@@ -1,24 +0,0 @@
|
||||
package me.chanjar.weixin.common.util.xml;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
|
||||
/**
|
||||
*
|
||||
* http://stackoverflow.com/questions/14193944/jaxb-marshalling-unmarshalling-with-cdata
|
||||
*
|
||||
* @author Daniel Qian
|
||||
*
|
||||
*/
|
||||
public class AdapterCDATA extends XmlAdapter<String, String> {
|
||||
|
||||
@Override
|
||||
public String marshal(String arg0) throws Exception {
|
||||
return "<![CDATA[" + arg0 + "]]>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String unmarshal(String arg0) throws Exception {
|
||||
return arg0;
|
||||
}
|
||||
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package me.chanjar.weixin.common.util.xml;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
|
||||
/**
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
public class MediaIdMarshaller extends XmlAdapter<String, String> {
|
||||
|
||||
@Override
|
||||
public String marshal(String arg0) throws Exception {
|
||||
return "<MediaId><![CDATA[" + arg0 + "]]></MediaId>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String unmarshal(String arg0) throws Exception {
|
||||
// do nothing
|
||||
return arg0;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package me.chanjar.weixin.common.util.xml;
|
||||
|
||||
import com.thoughtworks.xstream.converters.basic.StringConverter;
|
||||
|
||||
/**
|
||||
* Created by qianjia on 15/1/19.
|
||||
*/
|
||||
public class XStreamCDataConverter extends StringConverter {
|
||||
|
||||
@Override
|
||||
public String toString(Object obj) {
|
||||
return "<![CDATA[" + super.toString(obj) + "]]>";
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
package me.chanjar.weixin.common.util.xml;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.converters.basic.DoubleConverter;
|
||||
import com.thoughtworks.xstream.converters.basic.FloatConverter;
|
||||
import com.thoughtworks.xstream.converters.basic.IntConverter;
|
||||
import com.thoughtworks.xstream.core.util.QuickWriter;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
|
||||
import com.thoughtworks.xstream.io.xml.XppDriver;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Created by qianjia on 15/1/19.
|
||||
*/
|
||||
public class XStreamInitializer {
|
||||
|
||||
public static XStream getInstance() {
|
||||
XStream xstream = new XStream(new XppDriver() {
|
||||
@Override
|
||||
public HierarchicalStreamWriter createWriter(Writer out) {
|
||||
return new PrettyPrintWriter(out, getNameCoder()) {
|
||||
protected String PREFIX_CDATA = "<![CDATA[";
|
||||
protected String SUFFIX_CDATA = "]]>";
|
||||
protected String PREFIX_MEDIA_ID = "<MediaId>";
|
||||
protected String SUFFIX_MEDIA_ID = "</MediaId>";
|
||||
@Override
|
||||
protected void writeText(QuickWriter writer, String text) {
|
||||
if (text.startsWith(PREFIX_CDATA) && text.endsWith(SUFFIX_CDATA)) {
|
||||
writer.write(text);
|
||||
} else if (text.startsWith(PREFIX_MEDIA_ID) && text.endsWith(SUFFIX_MEDIA_ID)) {
|
||||
writer.write(text);
|
||||
} else {
|
||||
super.writeText(writer, text);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
xstream.setMode(XStream.NO_REFERENCES);
|
||||
return xstream;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package me.chanjar.weixin.common.util.xml;
|
||||
|
||||
/**
|
||||
* Created by qianjia on 15/1/19.
|
||||
*/
|
||||
public class XStreamMediaIdConverter extends XStreamCDataConverter {
|
||||
@Override
|
||||
public String toString(Object obj) {
|
||||
return "<MediaId>" + super.toString(obj) + "</MediaId>";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user