[QUESTION]
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 使用jastjson2 2.0.23 的FastJsonHttpMessageConverter时导致了过长的json格式的API请求返回字符的byte[]的问题?
*最开始我搭建的项目使用fastjson2===2.0.23作为json工具,并将其配置为httpMessageConverter, 导致接口返回byte[]配置如下:*
```java
@Configuration
public class FastJsonConfiguration {
@Bean
FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
com.alibaba.fastjson2.support.config.FastJsonConfig fastJsonConfig =
new com.alibaba.fastjson2.support.config.FastJsonConfig();
fastJsonConfig.setCharset(StandardCharsets.UTF_8);
fastJsonConfig.setWriterFeatures(
// long 转 string 丢失精度问题
JSONWriter.Feature.WriteLongAsString,
// // 保留map空的字段
// JSONWriter.Feature.WriteMapNullValue,
// //将List类型的null转成[]
// JSONWriter.Feature.WriteNullListAsEmpty,
// //将String类型的null转成""
//// JSONWriter.Feature.WriteNullStringAsEmpty,
// //将Boolean类型的null转成false
// JSONWriter.Feature.WriteNullBooleanAsFalse,
// 日期格式转换
JSONWriter.Feature.PrettyFormat
// //将空置输出为缺省值,Number类型的null都输出为0,String类型的null输出为"",数组和Collection类型的输出为[]
//// JSONWriter.Feature.NullAsDefaultValue
// 缺省值不输出
// JSONWriter.Feature.NotWriteDefaultValue
);
converter.setFastJsonConfig(fastJsonConfig);
return converter;
}
}
```
在开发中途, 添加了knife4j-openapi3-spring-boot-starter==4.1.0, 这时候出现了 API文档的/v3/api-docs/接口返回未一个很大的byte[], 截取数组的前面一小段发现数组为本该正常返回的api数据,如:
> {"openapi":"3.0.1","info":{"title":"OpenAPI definition","version":"v0"},"servers"[{"url":"http://127.0.0.1:10249/","description":"Generated server url"}],"tags":[{"name":"用...
后续我将fastjson2 版本更新至2.0.39(其他未做修改)后, /v3/api-docs/接口正确返回了,
* *问: 造成更新版本后问题解决的根本原因在哪?*
* *问: 我的FastJsonHttpMessageConverter 是否还可以优化?*
Contributor guide
Research direction
No source files or tests are named. Start by reproducing /v3/api-docs/ with fastjson2 2.0.23 and 2.0.39 using the shown FastJsonHttpMessageConverter configuration, then compare the response handling and dependency versions. Done means identifying why the response becomes a byte[] and documenting whether the converter configuration can be safely optimized.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring-boot
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100