有時候對象中會包含數組、Map、Collection 等常見集合。java
爲了存儲的便利性,默認提供集合的相關支持。數組
特性和普通字段保持一致,若是指定註解轉換,則以註解爲準。測試
用於演示集合的對象ui
public class UserCollection { private String[] arrays; private LinkedList<String> lists; private Map<String, String> maps; private Set<String> sets; //Getter/Setter/toString() }
/** * 構建基於集合的測試列表 * @return 列表 * @since 0.0.3 */ private List<UserCollection> buildCollectionList() { UserCollection user = new UserCollection(); String[] arrays = new String[]{"a", "b", "c"}; LinkedList<String> lists = new LinkedList<>(Arrays.asList(arrays)); Map<String, String> maps = new HashMap<>(); maps.put("key", "value"); maps.put("key2", "value2"); Set<String> sets = new HashSet<>(); sets.add("set1"); sets.add("set2"); user.setLists(lists); user.setArrays(arrays); user.setMaps(maps); user.setSets(sets); return Arrays.asList(user); }
public void collectionTest() { final String path = "src\\test\\resources\\collection.csv"; CsvWriteBs.newInstance(path) .write(buildCollectionList()); }
arrays,lists,maps,sets a|b,a|b|c,key2=value2|key=value,set1|set2
public void collectionTest() { final String path = "src\\test\\resources\\collection.csv"; List<UserCollection> userList = CsvReadBs.newInstance(path) .read(UserCollection.class); System.out.println(userList); }
[UserCollection{arrays=[a, b], lists=[a, b, c], maps={key=value, key2=value2}, sets=[set2, set1]}]
爲了保證 csv 以 ,
分隔的統一性。日誌
集合使用 |
進行分隔,其中 map 的 key/value 分隔,用到了 =
。code
在使用時要注意,不要包含上述的符號,不然會出現解析錯亂。對象