[BUG] Resource对象序列化打印日志之后,正常Resource返回的内容是空
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### spring项目中反回文件内容
service层构造FileSystemResource之后通过controller返回给前端
### 环境信息
*请填写以下信息:*
- OS信息: macos
- JDK信息:1.8
- 版本信息:fastjson[2.0.25]与 fastjson2[2.0.57] 均存在该问题
### 重现步骤
1. srevice层构造FileSystemResource直接返回
2. controller层存在日志切面,切面中对返回值进行tojsonString操作
这是切面中的实现
```java
logger.info("入参: " + joinPoint.getArgs());
Object result = joinPoint.proceed();
logger.info("返回值:" + JSONObject.toJSONString(result));
```
这是service层的实现
```java
FileSystemResource fileSystemResource = new FileSystemResource("aaa.txt");
return ResponseEntity.ok(fileSystemResource);
```
### 期待的正确结果
此时接口响应内容为空,从ResourceHttpMessageConverter.writeContent中得到的文件内容是空
Contributor guide
Research direction
Start with the controller logging flow and Spring's ResourceHttpMessageConverter.writeContent, reproducing the response before and after JSONObject.toJSONString(result) is called. Trace how the FileSystemResource is affected by serialization, then verify that the endpoint still returns the file contents after logging and add a focused regression test if the existing test structure supports it.
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
- Mostly clear
- Newbie friendliness
- 35/100