适用于Android的Spring,XmlPullParserException:未解决: -

时间:2014-01-16 09:59:51

标签: java android spring xml-parsing

我在我的项目中使用了一些公共API,此API返回XML响应。

我正在使用Spring for Android和Simple XML Serialization进行休息调用和XML映射。 一切都很顺利,但是一个方法可以返回带有一些特殊字符的文本(在我的情况下) - 所以当我调用这个方法时我会得到异常:

  

引起:   org.springframework.http.converter.HttpMessageNotReadableException:   无法阅读[课程   com.MyMappingClass];嵌套   异常是org.xmlpull.v1.XmlPullParserException:未解决:    - (position:TEXT @ 14:214 in java.io.InputStreamReader@64d962b0)

在RestTemplate中我正在使用下一个HttpMessageConverter:

List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
List<MediaType> mediaTypes = new ArrayList<MediaType>();
mediaTypes.add(MediaType.TEXT_HTML);
mediaTypes.add(MediaType.APPLICATION_XML);
SimpleXmlHttpMessageConverter messageConverter = new SimpleXmlHttpMessageConverter();
messageConverter.setSupportedMediaTypes(mediaTypes);
messageConverters.add(messageConverter);

在映射类中我有字段,它必须包含有文本:

@Element(name = "synopsis", required = false)
public String seriesSynopsis;

详细的堆栈跟踪:

Caused by: org.springframework.http.converter.HttpMessageNotReadableException: Could not read [class com.MyMappingClass]; nested exception is org.xmlpull.v1.XmlPullParserException: unresolved: &mdash; (position:TEXT @14:214 in java.io.InputStreamReader@64d962b0)
at org.springframework.http.converter.xml.SimpleXmlHttpMessageConverter.readInternal(SimpleXmlHttpMessageConverter.java:115)
at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:147)
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:76)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:655)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:641)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:484)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:415)

Caused by: org.xmlpull.v1.XmlPullParserException: unresolved: &mdash; (position:TEXT @14:214 in java.io.InputStreamReader@64d962b0)
at org.kxml2.io.KXmlParser.checkRelaxed(KXmlParser.java:302)
at org.kxml2.io.KXmlParser.readEntity(KXmlParser.java:1275)
at org.kxml2.io.KXmlParser.readValue(KXmlParser.java:1392)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:390)
at org.kxml2.io.KXmlParser.next(KXmlParser.java:310)
at org.simpleframework.xml.stream.PullReader.read(PullReader.java:105)
at org.simpleframework.xml.stream.PullReader.next(PullReader.java:89)
at org.simpleframework.xml.stream.PullReader.peek(PullReader.java:72)
at org.simpleframework.xml.stream.NodeReader.readValue(NodeReader.java:224)
at org.simpleframework.xml.stream.InputElement.getValue(InputElement.java:201)
at org.simpleframework.xml.core.Primitive.read(Primitive.java:163)
at org.simpleframework.xml.core.Primitive.readElement(Primitive.java:207)
at org.simpleframework.xml.core.Primitive.readElement(Primitive.java:189)
at org.simpleframework.xml.core.Primitive.read(Primitive.java:124)
at org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
at org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
at org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
at org.simpleframework.xml.core.Composite.readElement(Composite.j

还来自resporce的标题:

Content-Encoding →gzip
Content-Length →577
Content-Type →text/html; charset=UTF-8

我对Spring不太好,但是我可以以某种方式忽略特殊字符吗? 或者我该如何解决?

谢谢!

0 个答案:

没有答案