-
-
Notifications
You must be signed in to change notification settings - Fork 151
Open
Labels
Description
How to define the array separator as square brackets'[]'?E.g:1,[1,2,3],['name01','name02','name03'],'pen',1
The output of the following code is:1,'1,2,3','name01,name02,name03',pen,1
The expected output is:1,[1,2,3],['name01','name02','name03'],'pen',1
public class CsvTest {
public static void main(String[] args) throws JsonProcessingException {
OrderDto orderDto = new OrderDto(1L, "pen", 1, Arrays.asList("name01", "name02", "name03"), Arrays.asList(1, 2, 3));
CsvMapper mapper = new CsvMapper();
// schema from 'Pojo' definition
CsvSchema schema = mapper.schemaFor(OrderDto.class).withoutHeader().withAllowComments(true);
String csv = mapper.writer(schema).writeValueAsString(orderDto);
// 结果:1,'1,2,3','name01,name02,name03',pen,1
// 期待的结果:1,[1,2,3],['name01','name02','name03'],'pen',1
System.out.println(csv);
}
public static class OrderDto {
private Long user;
private String product;
private Integer amount;
private List<String> name_list;
private List<Integer> id_list;
public OrderDto() {
}
public OrderDto(Long user, String product, Integer amount, List<String> name_list, List<Integer> id_list) {
this.user = user;
this.product = product;
this.amount = amount;
this.name_list = name_list;
this.id_list = id_list;
}
public Long getUser() {
return user;
}
public void setUser(Long user) {
this.user = user;
}
public String getProduct() {
return product;
}
public void setProduct(String product) {
this.product = product;
}
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amount) {
this.amount = amount;
}
public List<String> getName_list() {
return name_list;
}
public void setName_list(List<String> name_list) {
this.name_list = name_list;
}
public List<Integer> getId_list() {
return id_list;
}
public void setId_list(List<Integer> id_list) {
this.id_list = id_list;
}
@Override
public String toString() {
return "OrderDto{" +
"user=" + user +
", product='" + product + '\'' +
", amount=" + amount +
", name_list=" + name_list +
", id_list=" + id_list +
'}';
}
}
}