<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-csv -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-csv</artifactId>
<version>2.14.0-rc3</version>
</dependency>
val zhiPinFile = File("...")
val jobList = ArrayList<Job>()
val csvMapper : CsvMapper = CsvMapper()
// schemaFor(Job::class.java) 需要序列化的对象类
// withHeader() 输出到csv文件第一行,不加则没有
val csvSchema : CsvSchema = csvMapper.schemaFor(Job::class.java).withHeader()
csvMapper.writer(csvSchema).writeValues(zhiPinFile).write(jobList)
添加注解,不加默认按照首字母排序
@JsonPropertyOrder("name","description")
data Job class(val name : String, val description : String){}
参考:
How to serialize object to CSV file? Jackson JsonMappingException: Unrecognized column 'C': known columns {"A","B"} jackson-data-format-csv 读取csv文件——高级配置及原理解析
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有