LianjiaTech / retrofit-spring-boot-starter

A spring-boot starter for retrofit, supports rapid integration and feature enhancements.(适用于retrofit的spring-boot-starter,支持快速集成和功能增强)
Apache License 2.0
1.78k stars 340 forks source link

@RetrofitClient 配置converterFactories = {JaxbConverterFactory.class}解析XML异常 #57

Closed liangxp closed 2 years ago

liangxp commented 3 years ago

JDK:1.8 retrofit-spring-boot-starter版本:2.2.7 异常效果: 依然走默认JacksonConverterFactory解析,不走JaxbConverterFactory解析返回数据。 @RetrofitClient(baseUrl = "http://xxx.com",converterFactories = {JaxbConverterFactory.class}) @QooJpSign(exclude = {"/GMKT.INC.Front.QAPIService/CertificationAPI.CreateCertificationKey"}) @Retry public interface QooJpXmlApi 如上注解已经配置JaxbConverterFactory,但是系统依然走默认配置JacksonConverterFactory 异常如下: Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false') at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 2] at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1851) at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:707) at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:632) at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1947) at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:776) at com.fasterxml.jackson.databind.ObjectReader._initForReading(ObjectReader.java:357) at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:2064) at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1485) at retrofit2.converter.jackson.JacksonResponseBodyConverter.convert(JacksonResponseBodyConverter.java:33) at retrofit2.converter.jackson.JacksonResponseBodyConverter.convert(JacksonResponseBodyConverter.java:23) at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:243) at retrofit2.OkHttpCall.execute(OkHttpCall.java:204) at com.github.lianjiatech.retrofit.spring.boot.core.BodyCallAdapterFactory$BodyCallAdapter.adapt(BodyCallAdapterFactory.java:77) ... 104 more

chentianming11 commented 3 years ago

还需要将JaxbConverterFactory配置成Spring Bean才能生效~