Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public enum class KotlinFeature(internal val enabledByDefault: Boolean) {

public companion object {
internal val defaults
get() = values().fold(BitSet(Int.SIZE_BITS)) { acc, cur ->
get() = entries.fold(BitSet(Int.SIZE_BITS)) { acc, cur ->
acc.apply { if (cur.enabledByDefault) this.or(cur.bitSet) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class KotlinModuleTest {
@Test
fun setKotlinFeatureTest() {
val builder = KotlinModule.Builder().apply {
KotlinFeature.values().forEach { enable(it) }
KotlinFeature.entries.forEach { enable(it) }
}

assertTrue(builder.isEnabled(KotlinFeature.NullToEmptyCollection))
Expand All @@ -27,7 +27,7 @@ class KotlinModuleTest {
assertTrue(builder.isEnabled(KotlinFeature.UseJavaDurationConversion))

builder.apply {
KotlinFeature.values().forEach { disable(it) }
KotlinFeature.entries.forEach { disable(it) }
}

assertFalse(builder.isEnabled(KotlinFeature.NullToEmptyCollection))
Expand Down Expand Up @@ -84,7 +84,7 @@ class KotlinModuleTest {
val module = KotlinModule.Builder().apply {
withCacheSize(KotlinModule.CacheSize(123, 321))

KotlinFeature.values().forEach {
KotlinFeature.entries.forEach {
configure(it, enabled)
}
}.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,42 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

private class FailNullForPrimitiveTest {
data class Dto(
val mapper = jacksonObjectMapper()
.enable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)

data class NoDefaultValue(
val foo: Int,
val bar: Int?
)

@Test
fun test() {
val mapper = jacksonObjectMapper()
.enable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES)
fun noDefaultValueTest() {
// If no default value is set, it will fail if undefined or null is entered
assertThrows<MismatchedInputException> {
mapper.readValue<NoDefaultValue>("{}")
}

assertThrows<MismatchedInputException> {
mapper.readValue<Dto>("{}")
mapper.readValue<NoDefaultValue>("""{"foo":null}""")
}

assertEquals(NoDefaultValue(0, null), mapper.readValue<NoDefaultValue>("""{"foo":0}"""))
}

data class HasDefaultValue(
val foo: Int = -1,
val bar: Int? = -1
)

@Test
fun hasDefaultValueTest() {
// If a default value is set, an input of undefined will succeed, but null will fail
assertEquals(HasDefaultValue(-1, -1), mapper.readValue<HasDefaultValue>("{}"))

assertThrows<MismatchedInputException> {
mapper.readValue<Dto>("""{"foo":null}""")
mapper.readValue<HasDefaultValue>("""{"foo":null}""")
}

assertEquals(Dto(0, null), mapper.readValue<Dto>("""{"foo":0}"""))
assertEquals(HasDefaultValue(0, null), mapper.readValue<HasDefaultValue>("""{"foo":0, "bar":null}"""))
}
}
Loading