@Test void getDataFromFile_DataPayload() throws IOException { MultipartFile multipartFile = resolveMultipartFile("data_payload_template.yml"); Optional<DataPayload> data = parseService.getDataFromFile(multipartFile, new TypeReference<>() { }); validateDataPayload(data); }
public <T> Optional<T> getDataFromFile(MultipartFile input, TypeReference<T> typeReference) { try { return Optional.ofNullable(objectMapper.readValue(input.getInputStream(), typeReference)); } catch (IOException e) { log.error("Could not map file to Object. \n {}", e.getMessage()); return Optional.empty(); } }
ParseService { public <T> Optional<T> getDataFromFile(MultipartFile input, TypeReference<T> typeReference) { try { return Optional.ofNullable(objectMapper.readValue(input.getInputStream(), typeReference)); } catch (IOException e) { log.error("Could not map file to Object. \n {}", e.getMessage()); return Optional.empty(); } } }
ParseService { public <T> Optional<T> getDataFromFile(MultipartFile input, TypeReference<T> typeReference) { try { return Optional.ofNullable(objectMapper.readValue(input.getInputStream(), typeReference)); } catch (IOException e) { log.error("Could not map file to Object. \n {}", e.getMessage()); return Optional.empty(); } }  }
ParseService { public <T> Optional<T> getDataFromFile(MultipartFile input, TypeReference<T> typeReference) { try { return Optional.ofNullable(objectMapper.readValue(input.getInputStream(), typeReference)); } catch (IOException e) { log.error("Could not map file to Object. \n {}", e.getMessage()); return Optional.empty(); } }  Optional<T> getDataFromFile(MultipartFile input, TypeReference<T> typeReference); Optional<DataPayload> getDefaultData(); byte[] generateFileByPayload(DataPayload data); List<T> convertFileToTargetObject(MultipartFile file, Class<T> target); }
ParseService { public <T> Optional<T> getDataFromFile(MultipartFile input, TypeReference<T> typeReference) { try { return Optional.ofNullable(objectMapper.readValue(input.getInputStream(), typeReference)); } catch (IOException e) { log.error("Could not map file to Object. \n {}", e.getMessage()); return Optional.empty(); } }  Optional<T> getDataFromFile(MultipartFile input, TypeReference<T> typeReference); Optional<DataPayload> getDefaultData(); byte[] generateFileByPayload(DataPayload data); List<T> convertFileToTargetObject(MultipartFile file, Class<T> target);  }