@Test void convertMultiPartToFile() throws IOException { List<UserTransaction> transactions = parseService.convertFileToTargetObject(resolveMultipartFile("transactions_template.csv"), UserTransaction.class); assertThat(transactions).isNotEmpty(); assertEquals(buildSingleUserTransaction(), transactions.get(0)); }
public <T> List<T> convertFileToTargetObject(MultipartFile file, Class<T> target) { if (file == null) { throw new TppException("No file uploaded!", 400); } try { InputStreamReader streamReader = new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8); CsvToBean<T> csvToBean = new CsvToBeanBuilder<T>(streamReader) .withType(target) .withIgnoreLeadingWhiteSpace(true) .build(); return csvToBean.parse(); } catch (IOException e) { log.error("Can't convert file to target class: {}", target.getSimpleName(), e); throw new TppException("Can't convert file to target class", 400); } }
ParseService { public <T> List<T> convertFileToTargetObject(MultipartFile file, Class<T> target) { if (file == null) { throw new TppException("No file uploaded!", 400); } try { InputStreamReader streamReader = new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8); CsvToBean<T> csvToBean = new CsvToBeanBuilder<T>(streamReader) .withType(target) .withIgnoreLeadingWhiteSpace(true) .build(); return csvToBean.parse(); } catch (IOException e) { log.error("Can't convert file to target class: {}", target.getSimpleName(), e); throw new TppException("Can't convert file to target class", 400); } } }
ParseService { public <T> List<T> convertFileToTargetObject(MultipartFile file, Class<T> target) { if (file == null) { throw new TppException("No file uploaded!", 400); } try { InputStreamReader streamReader = new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8); CsvToBean<T> csvToBean = new CsvToBeanBuilder<T>(streamReader) .withType(target) .withIgnoreLeadingWhiteSpace(true) .build(); return csvToBean.parse(); } catch (IOException e) { log.error("Can't convert file to target class: {}", target.getSimpleName(), e); throw new TppException("Can't convert file to target class", 400); } }  }
ParseService { public <T> List<T> convertFileToTargetObject(MultipartFile file, Class<T> target) { if (file == null) { throw new TppException("No file uploaded!", 400); } try { InputStreamReader streamReader = new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8); CsvToBean<T> csvToBean = new CsvToBeanBuilder<T>(streamReader) .withType(target) .withIgnoreLeadingWhiteSpace(true) .build(); return csvToBean.parse(); } catch (IOException e) { log.error("Can't convert file to target class: {}", target.getSimpleName(), e); throw new TppException("Can't convert file to target class", 400); } }  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> List<T> convertFileToTargetObject(MultipartFile file, Class<T> target) { if (file == null) { throw new TppException("No file uploaded!", 400); } try { InputStreamReader streamReader = new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8); CsvToBean<T> csvToBean = new CsvToBeanBuilder<T>(streamReader) .withType(target) .withIgnoreLeadingWhiteSpace(true) .build(); return csvToBean.parse(); } catch (IOException e) { log.error("Can't convert file to target class: {}", target.getSimpleName(), e); throw new TppException("Can't convert file to target class", 400); } }  Optional<T> getDataFromFile(MultipartFile input, TypeReference<T> typeReference); Optional<DataPayload> getDefaultData(); byte[] generateFileByPayload(DataPayload data); List<T> convertFileToTargetObject(MultipartFile file, Class<T> target);  }