-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from ProjectMapK/fix/738
Fixed a problem where the `Nulls` setting was ignored if the input was `undefined`
- Loading branch information
Showing
4 changed files
with
96 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...t/kotlin/io/github/projectmapk/jackson/module/kogera/zIntegration/deser/JsonSetterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.github.projectmapk.jackson.module.kogera.zIntegration.deser | ||
|
||
import com.fasterxml.jackson.annotation.JsonSetter | ||
import com.fasterxml.jackson.annotation.Nulls | ||
import com.fasterxml.jackson.databind.exc.InvalidNullException | ||
import io.github.projectmapk.jackson.module.kogera.jacksonObjectMapper | ||
import io.github.projectmapk.jackson.module.kogera.readValue | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Nested | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
|
||
class JsonSetterTest { | ||
val mapper = jacksonObjectMapper() | ||
|
||
data class NullsSkip(@JsonSetter(nulls = Nulls.SKIP) val v: Int = -1) | ||
|
||
@Test | ||
fun nullsSkip() { | ||
val d = mapper.readValue<NullsSkip>("""{"v":null}""") | ||
|
||
assertEquals(-1, d.v) | ||
} | ||
|
||
data class NullsFail(@JsonSetter(nulls = Nulls.FAIL) val v: Int?) | ||
|
||
@Nested | ||
inner class NullsFailTest { | ||
@Test | ||
fun onNull() { | ||
assertThrows<InvalidNullException> { | ||
mapper.readValue<NullsFail>("""{"v":null}""") | ||
} | ||
} | ||
|
||
@Test | ||
fun onMissing() { | ||
assertThrows<InvalidNullException> { | ||
mapper.readValue<NullsFail>("""{}""") | ||
} | ||
} | ||
} | ||
|
||
data class NullsAsEmpty(@JsonSetter(nulls = Nulls.AS_EMPTY) val v: Collection<*>) | ||
|
||
@Nested | ||
inner class NullsAsEmptyTest { | ||
@Test | ||
fun onNull() { | ||
val d = mapper.readValue<NullsAsEmpty>("""{"v":null}""") | ||
assertTrue(d.v.isEmpty()) | ||
} | ||
|
||
@Test | ||
fun onMissing() { | ||
val d = mapper.readValue<NullsAsEmpty>("""{}""") | ||
assertTrue(d.v.isEmpty()) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ojectmapk/jackson/module/kogera/zIntegration/deser/deserializer/MissingAbsentValueTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.github.projectmapk.jackson.module.kogera.zIntegration.deser.deserializer | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer | ||
import io.github.projectmapk.jackson.module.kogera.jacksonObjectMapper | ||
import io.github.projectmapk.jackson.module.kogera.readValue | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class MissingAbsentValueTest { | ||
class Deser : StdDeserializer<Int>(Int::class.java) { | ||
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): Int { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getAbsentValue(ctxt: DeserializationContext) = -1 | ||
} | ||
|
||
data class D( | ||
@JsonDeserialize(using = Deser::class) val foo: Int, | ||
@JsonDeserialize(using = Deser::class) val bar: Int? | ||
) | ||
|
||
@Test | ||
fun test() { | ||
val mapper = jacksonObjectMapper() | ||
val result = mapper.readValue<D>("{}") | ||
|
||
assertEquals(D(-1, -1), result) | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
src/test/kotlin/io/github/projectmapk/jackson/module/kogera/zPorted/test/github/Github526.kt
This file was deleted.
Oops, something went wrong.