Csv File to Kotlin Data Class Parser
Currently, it requires to have@ExperimentalStdlibApion the class/method using this Library.
Requires kotlin-csv by doyaaaaaken for reading csv file.
- Change Log - updates and bug fixes
- No hard configuration
- No invasive annotations to data class
- Custom mapping
- Nullable Data Types
- Short
- Int
- Long
- Float
- Double
- Boolean
- String
- LocalTime
- LocalDateTime
- LocalDate
- Custom Formatting
//doyaaaaaken's kotlin-csv
implementation("com.github.doyaaaaaken:kotlin-csv-jvm:0.11.0")
//kotlin-grass
implementation("com.vhl.blackmo:kotlin-grass-jvm:0.4.1")Please use the following version
//doyaaaaaken's kotlin-csv
implementation("com.github.doyaaaaaken:kotlin-csv-jvm:0.10.4")
//kotlin-grass
implementation("com.vhl.blackmo:kotlin-grass-jvm:0.3.0")| short | int | long | float | double | boolean | string |
|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3.0 | 4.0 | true | hello |
data classPrimitiveTypes(
valshort:Short,
valint:Int,
vallong:Long,
valfloat:Float,
valdouble:Double,
valboolean:Boolean,
valstring:String
)If a variable in your data class is a nullable, all you have to do is mark it with ?
data classNullableData(
valnullableString:String?,
valnullableInt:Int? = null,
...
)val csvContents = csvReader().readAllWithHeader(file)
val dataClasses = grass<PrimitiveTypes>().harvest(csvContents)| Option | default value | description |
|---|---|---|
| dateFormat | yyyy-MM-dd | date format |
| timeFormat | HH:mm | time format |
| dateTimeSeparator | (space) | date time separator |
| trimWhiteSpace | true | trims white spaces on csv entries |
| customKeyMap | null | Map<String,String> custom key mapping |
| time | datetime | date |
|---|---|---|
| 12:00 | 2020-12-31 12:00 | 2020-12-31 |
data classDateTimeTypes(
valtime:LocalTime,
valdatetime:LocalDateTime,
valdate:LocalDate,
)val grass = grass<DateTimeTypes> {
dateFormat ="MM-dd-yyyy"
timeFormat ="HH:mm:ss"
dateTimeSeparator ="/"
}| hour | birthdate |
|---|---|
| 12:00 | 2020-12-31 |
data classDateTime(
valtime:LocalTime,
valdate:LocalDate,
)
val grass = grass<DateTimeTypes> {
customKeyMap =mapOf("hour" to "time", "birthdate" to "date")
}Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
Copyright © 2020 blackmo18.
This project is Apache License 2.0 licensed.
This project inspired ❤️ by kotlin-csv
