HandleXiaomanData.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package com.fjhx.customer.handle;
  2. import com.fjhx.customer.entity.xiaoman.po.XiaomanCustomer;
  3. import com.fasterxml.jackson.core.type.TypeReference;
  4. import com.fasterxml.jackson.databind.ObjectMapper;
  5. import com.fjhx.customer.entity.xiaoman.vo.CustomerApiVo;
  6. import com.fjhx.customer.entity.xiaoman.vo.CustomerListApiVo;
  7. import java.io.BufferedReader;
  8. import java.io.FileReader;
  9. import java.io.IOException;
  10. public class HandleXiaomanData {
  11. public static void main(String[] args) {
  12. String filePath = "D:\\java_conding\\erhong\\hx-customer\\src\\main\\java\\com\\fjhx\\customer\\handle\\aaa.json";
  13. String jsonData = "";
  14. try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
  15. String line;
  16. while ((line = br.readLine()) != null) {
  17. jsonData += line;
  18. }
  19. handleList(jsonData, new TypeReference<R<CustomerListApiVo>>() {});
  20. } catch (IOException e) {
  21. e.printStackTrace();
  22. }
  23. }
  24. public static <T> T handleList(String res, TypeReference<R<T>> typeReference) {
  25. ObjectMapper objectMapper = new ObjectMapper();
  26. try {
  27. R<T> result = objectMapper.readValue(res, typeReference);
  28. if (result.isOk()) {
  29. return result.getData();
  30. }
  31. return null;
  32. } catch (Exception e) {
  33. e.printStackTrace();
  34. return null;
  35. }
  36. }
  37. }