请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

我在使用feign发请求的时候出现json错误。。。

feign的配置

feign:
  hystrix:
    enabled: false
  httpclient:
    enabled: true
  compression:
    request:
      enabled: true
      # 限制格式
      mime-types: text/xml,application/xml,application/json
      # 限制大小
      min-request-size: 2480

错误信息:

Caused by: org.springframework.web.client.RestClientException: Error while extracting response for type [class com.allahbin.cloud.userInfo] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens
 at [Source: (PushbackInputStream); line: 1, column: 2]
	at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:117)
	at org.springframework.cloud.openfeign.support.SpringDecoder.decode(SpringDecoder.java:59)
	at org.springframework.cloud.openfeign.support.ResponseEntityDecoder.decode(ResponseEntityDecoder.java:62)
	at feign.optionals.OptionalDecoder.decode(OptionalDecoder.java:36)
	at feign.SynchronousMethodHandler.decode(SynchronousMethodHandler.java:176)
	... 86 common frames omitted
Caused by: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens
 at [Source: (PushbackInputStream); line: 1, column: 2]
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:245)
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:227)
	at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:102)
	... 90 common frames omitted
Caused by: com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\r, \n, \t) is allowed between tokens
 at [Source: (PushbackInputStream); line: 1, column: 2]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1804)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:693)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._throwInvalidSpace(ParserMinimalBase.java:644)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._skipWSOrEnd(UTF8StreamJsonParser.java:2951)
	at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:691)
	at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4142)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4001)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3085)
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:239)
	... 92 common frames omitted
2019-12-09 00:00:58,112 [http-nio-7205-exec-1] ERROR o.s.c.s.i.w.ExceptionLoggingFilter [ExceptionLoggingFilter.java : 54]- Uncaught exception thrown

正在回答 回答被采纳积分+3

1回答

提问者 阿拉斌 2019-12-09 15:41:54

醉了,我在 yml给tomcat的配置上加上了gzip的压缩,然后feign再打开就会报错

0 回复 有任何疑惑可以回复我~
  • Allen #1
    光看错误看起来是返回的内容有特殊字符, Jackson无法解析了
    回复 有任何疑惑可以回复我~ 2019-12-10 14:21:05
  • 提问者 阿拉斌 回复 Allen #2
    我感觉是重复压缩了,然后解压出来就是乱码了
    回复 有任何疑惑可以回复我~ 2019-12-12 10:35:29
  • Allen 回复 提问者 阿拉斌 #3
    测试过么
    回复 有任何疑惑可以回复我~ 2019-12-12 18:35:36
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信