kotlinx-serialization-csv

This module contains the CSV-Format.

Usage

FirstName,LastName
John,Doe

To decode from the given CSV string:

@Serializable
data class Names(val firstName: String, val lastName: String)

CSVFormat.decodeFromString(Names.serializer(), csv)

And to encode:

CSVFormat.encodeToString(Names.serializer(), Names("John", "Doe"))

"""
firstName,lastName
John,Doe
"""

Limitations

  • The order of the properties of the class must match the order of the header/fields!

  • The header is ignored.

  • Inner lists are not supported, eg. data class NotSupported(val innerList: List<String>)

Packages

Link copied to clipboard
common