Skip to content

Commit

Permalink
CSV: Ignore nullable values at the end (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
hfhbd committed Feb 29, 2024
1 parent 0408470 commit 2a2ad02
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions gradle/build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ dependencyResolutionManagement {
}
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}

rootProject.name = "build-logic"
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public class CSVDecoder(
return this
}

override fun decodeNotNullMark(): Boolean = data[currentRow][index] != ""
override fun decodeNotNullMark(): Boolean {
val value = data[currentRow].getOrNull(index)
return value != null && value != ""
}

override fun endStructure(descriptor: SerialDescriptor) {
level -= 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ class CsvDecoderTest {
)
}

@Test
fun nullableSecondWithoutComma() {
val csv = """
bar,baz
42
""".trimIndent()

assertEquals(
expected = FooNull(bar = 42, baz = null),
actual = CSVFormat.decodeFromString(FooNull.serializer(), csv)
)
}

@Test
fun nullableFirst() {
val csv = """
Expand Down

0 comments on commit 2a2ad02

Please sign in to comment.