找不到类java.io.ByteArrayInputStream ----

时间:2017-12-05 05:29:51

标签: java rest spring-mvc

我想将miltipart文件上传到服务器,但它给了我错误

  

无法写内容:找不到类的序列化程序   java.io.ByteArrayInputStream并未找到要创建的属性   BeanSerializer(避免exceptiondisable SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过参考链:   org.springframework.util.LinkedMultiValueMap["file"]->java.util.LinkedList[0]->org.springframework.core.io.ByteArrayResource["inputStream"]

请在下面找到我的Spring WebMVC方法。

public UserResponseDTO uploadFiles(MultipartFile file, String clientId, String syncingType, String feedformat  , String emails, String welcomeMail, String authMode) {
    log.info("uploadFiles()");
    UserResponseDTO response = new UserResponseDTO();
    if (file != null && !file.isEmpty() && clientId != null || !clientId.isEmpty() && syncingType != null || !syncingType.isEmpty() && feedformat != null || !feedformat.isEmpty()) {
        String uri = uploadBulkUser;
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");
        headers.add(headerName, headerValue);
        List<String> tempFileNames = new ArrayList<>();
        String tempFileName;
        FileOutputStream fo;
        MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
        try {
            objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false);
            map.add("file", new ByteArrayResource(file.getBytes()));
        } catch (IOException e) {
            e.printStackTrace();
        }
        map.add("clientId", clientId);
        map.add("syncType", syncingType);
        map.add("feedformat", feedformat);
        map.add("emails", emails);
        map.add("welcomeMail", welcomeMail);
        map.add("authMode", authMode);
        HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<MultiValueMap<String, Object>>(map, headers);
        try {
            ResponseEntity<String> resposne = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class);
            log.info("resposne", resposne);
        } catch (RestClientException e) {
            log.error("RestClientException occured while User Role And Status Preference details from url :- "  + uri, e);
            ResponseUtil.populateCommonResponseFieldsAs(response, "Some error occured. Please contact customer support.", "failure", false);
        } catch (Exception e) {
            log.error("Exception occured while parsing User Role and Status response.", e);
            ResponseUtil.populateCommonResponseFieldsAs(response, "Some error occured. Please contact customer support.", "failure", false);
        }

0 个答案:

没有答案