[BUG]A服务通过feign调用B服务,传参包含byte[]参数就会报JSON parse error: illegal input, offset 1, char �; nested exception is com.alibaba.fastjson.JSONException: illegal input, offset 1, char �错误
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
A服务通过feign调用B服务,传参包含byte[]参数就会报JSON parse error: illegal input, offset 1, char ; nested exception is com.alibaba.fastjson.JSONException: illegal input, offset 1, char 错误
### 环境信息
*请填写以下信息:*
- OS信息: windows
- JDK信息: 1.8
- 版本信息:Fastjson2.0.39
### 重现步骤
*如何操作可以重现该问题:*
需要A、B两个服务应用
A服务通过Feign调用
@PostMapping("/test2")
public void test2(@Param("file") MultipartFile file){
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("c", file.getInputStream().readAllBytes());
String test = bdcOdsFeign.test(jsonObject);
System.out.println(test);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
B服务接口
@PostMapping("/test")
String test(@RequestBody JSONObject jhListWjbf){
return JSONUtil.toJsonStr(jhListWjbf);
}
### 期待的正确结果
*对您期望发生的结果进行清晰简洁的描述。*
### 相关日志输出
*请复制并粘贴任何相关的日志输出。*
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: illegal input, offset 1, char ; nested exception is com.alibaba.fastjson.JSONException: illegal input, offset 1, char
at com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.readType(FastJsonHttpMessageConverter.java:128)
at com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.read(FastJsonHttpMessageConverter.java:87)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:204)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:126)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:166)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:665)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*
Caused by: com.alibaba.fastjson.JSONException: illegal input, offset 1, char
at com.alibaba.fastjson.JSON.parseObject(JSON.java:779)
at com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.readType(FastJsonHttpMessageConverter.java:126)
... 93 common frames omitted
Caused by: com.alibaba.fastjson2.JSONException: illegal input, offset 1, char
at com.alibaba.fastjson2.JSONReader.read(JSONReader.java:2043)
at com.alibaba.fastjson2.reader.ObjectReaderImplMap.readObject(ObjectReaderImplMap.java:434)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:769)
... 94 common frames omitted
Contributor guide
Research direction
Reproduce the two-service Feign request described in the issue with a JSONObject containing a byte[] parameter, then start from FastJsonHttpMessageConverter.java:126 and read the related JSON.parseObject and JSONReader stack frames. Confirm the expected handling of the request and add a regression check if the relevant test location can be identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100