FastJson 使用问题:Java操作本地文件被清空,大小变成0

问题

发现一个文件生成以后,如果不通过接口发送,大小就正常,通过接口发送,文件大小就变成0了,发送的文件也是0 空文件

代码

java 复制代码
		MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
        FileSystemResource fileSystemResource = new FileSystemResource(fileName);
        form.add("file", fileSystemResource);
        HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(form, requestHeaders);
        String url = Consts.HTTP + IpUtils.getIpAddress(ip) + Consts.SEMICOLON + port + contextPath + uploadServletPath;
        log.info("导出-begin----------{},{}", url, JSON.toJSONString(form));
        ResponseEntity<Msg> responseEntity = restTemplate.postForEntity(url, entity, Msg.class);  

原因

JSON.toJSONString(form) 序列化form表单时时会清空文件内容

处理办法

不使用JSON.toJSONString处理form表单

原理

todo 闲了再看原理

相关推荐
p***95003 分钟前
Plugin ‘org.springframework.bootspring-boot-maven-plugin‘ not found的解决方法
java·maven
JienDa3 分钟前
JienDa聊PHP:算命平台实战中主流PHP框架的协同架构方略
开发语言·架构·php
h***066513 分钟前
Spring Boot 集成 Kettle
java·spring boot·后端
爱写代码的小朋友22 分钟前
21天学通Python全栈开发实战指南
开发语言·python
苦荞米23 分钟前
异步方法-C#中坑最大最深的功能
开发语言·c#
软件测试曦曦26 分钟前
使用Python接口自动化测试post请求和get请求,获取请求返回值
开发语言·自动化测试·软件测试·python·功能测试·程序人生·职场和发展
旷野说41 分钟前
如何用 Redpanda + 本地事务,实现“发消息 + 写 DB” 的强一致性!
java·数据库·kafka
p***s9144 分钟前
Windows安装Rust环境(详细教程)
开发语言·windows·rust
unclecss1 小时前
从 0 到 1 落地 SSE:Spring Boot 3 实战 Server-Sent Events 推送全链路
java·spring boot·后端·http·sse
e***95641 小时前
springboot-自定义注解
java·spring boot·spring