【easyexcel报错】com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.54

【日常POC问题记录,easyexcel报错】
【记录点】sprintBoot单项目正常使用,微服务项目中报错
【报错信息】

com.alibaba.fastjson.JSONException: write javaBean error, fastjson version 1.2.54, class org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile, fieldName : 0, write javaBean error, fastjson version 1.2.54, class org.springframework.web.multipart.MultipartFileResource, fieldName : resource

【问题代码】

@PostMapping("/testExcel22")
public Payload testExcel(MultipartFile file) {
    try {
        EasyExcel.read(file.getInputStream(), TestExcel.class,new ExcelImportMemberAddressListener()).sheet().doRead();
    } catch (Exception e) {
        e.printStackTrace();
        throw new ApplicationException("XXXXXexcel解析失败");
    }
    return new Payload();
}

【原因】MultipartFile与easyexcel打印日志类冲突
【解决办法】把MultipartFile放在实体使用

@Data
public class FormData {

    @JSONField(serialize = false)
    private MultipartFile file;

    private String name;

    private String filename;

}

@PostMapping("/testExcel22")
public Payload testExcel(FormData formData) {
    try {
        EasyExcel.read(formData.getFile().getInputStream(), TestExcel.class,new ExcelImportMemberAddressListener()).sheet().doRead();

    } catch (Exception e) {
        e.printStackTrace();
        throw new ApplicationException("会员档案(收货地址)导入-门店excel解析失败");
    }
    return new Payload();
}

你可能感兴趣的:(Java,java,微服务)