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 闲了再看原理

相关推荐
q***78786 分钟前
Spring Boot的项目结构
java·spring boot·后端
应用市场24 分钟前
Qt QTreeView深度解析:从原理到实战应用
开发语言·数据库·qt
q***965832 分钟前
Spring Data JDBC 详解
java·数据库·spring
ooooooctober34 分钟前
PHP代码审计框架性思维的建立
android·开发语言·php
Kuo-Teng35 分钟前
LeetCode 118: Pascal‘s Triangle
java·算法·leetcode·职场和发展·动态规划
倚肆1 小时前
HttpServletResponse 与 ResponseEntity 详解
java·后端·spring
悟能不能悟1 小时前
java List怎么转换为Vector
java·windows·list
yaoxin5211231 小时前
241. Java 集合 - 使用 Collections 工厂类处理集合
java·windows
依_旧1 小时前
【玩转全栈】----Django基本配置和介绍
java·后端
864记忆1 小时前
Qt Widgets 模块中的函数详解
开发语言·qt