Skip to content
Merged

2.19 #985

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 @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.exc.InputCoercionException
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import java.math.BigInteger
import kotlin.test.assertEquals
Expand All @@ -13,7 +14,8 @@ internal class UnsignedNumbersOnKeyTest {
val MAPPER = jacksonObjectMapper()
}

class ForUByte {
@Nested
inner class ForUByte {
private fun makeSrc(v: Int): String = MAPPER.writeValueAsString(mapOf(v to 0))

@Test
Expand All @@ -37,7 +39,8 @@ internal class UnsignedNumbersOnKeyTest {
}
}

class ForUShort {
@Nested
inner class ForUShort {
private fun makeSrc(v: Int): String = MAPPER.writeValueAsString(mapOf(v to 0))

@Test
Expand All @@ -61,7 +64,8 @@ internal class UnsignedNumbersOnKeyTest {
}
}

class ForUInt {
@Nested
inner class ForUInt {
private fun makeSrc(v: Long): String = MAPPER.writeValueAsString(mapOf(v to 0))

@Test
Expand All @@ -85,7 +89,8 @@ internal class UnsignedNumbersOnKeyTest {
}
}

class ForULong {
@Nested
inner class ForULong {
private fun makeSrc(v: BigInteger): String = MAPPER.writeValueAsString(mapOf(v to 0))

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import kotlin.test.assertEquals
class TestGithub101_JacksonInjectTest {
@Test
fun `JacksonInject-annotated parameters are populated when constructing Kotlin data classes`() {
val mapper = jacksonObjectMapper()
val contextualValue = UUID.randomUUID()
assertEquals(SomeDatum("test", contextualValue),
mapper.readerFor(SomeDatum::class.java)
.with(InjectableValues.Std(mapOf("context" to contextualValue)))
.readValue("""{ "value": "test" }"""))
val reader = jacksonObjectMapper()
.readerFor(SomeDatum::class.java)
.with(InjectableValues.Std(mapOf("context" to contextualValue)))
assertEquals(
SomeDatum("test", contextualValue),
reader.readValue("""{ "value": "test" }""")
)
}

data class SomeDatum(val value: String, @JacksonInject("context") val contextualValue: UUID)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fasterxml.jackson.module.kotlin.test.github

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -32,7 +33,8 @@ class TestGithub148 {
val type: IncorrectType
)

class DemoApplicationTests {
@Nested
inner class DemoApplicationTests {
val objectMapper = jacksonObjectMapper()

@Test
Expand All @@ -45,4 +47,4 @@ class TestGithub148 {
assertEquals("{\"name\":\"incorrent\",\"type\":\"TYPEA\"}", objectMapper.writeValueAsString(IncorrentBean("incorrent", IncorrectType.TYPEA)))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TestGithub168 {
class TestClass(@JsonProperty(value = "foo", required = true) foo: String?, val baz: String)

@Test
fun testIfRequiredIsReallyRequiredWhenNullused() {
fun testIfRequiredIsReallyRequiredWhenNullUsed() {
val obj = jacksonObjectMapper().readValue<TestClass>("""{"foo":null,"baz":"whatever"}""")
assertEquals("whatever", obj.baz)
}
Expand All @@ -27,7 +27,7 @@ class TestGithub168 {
}

@Test
fun testIfRequiredIsReallyRequiredWhenVauePresent() {
fun testIfRequiredIsReallyRequiredWhenValuePresent() {
val obj = jacksonObjectMapper().readValue<TestClass>("""{"foo":"yay!","baz":"whatever"}""")
assertEquals("whatever", obj.baz)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.InjectableValues
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import kotlin.math.exp
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals

class Github722 {
data class FailingDto @JsonCreator constructor(
Expand Down Expand Up @@ -39,11 +37,13 @@ class Github722 {
@Test
fun failing() {
// The kotlin mapper uses the Kotlin default value instead of the Inject value.
val kotlinMapper = jacksonObjectMapper()
val result = kotlinMapper.readerFor(FailingDto::class.java)
val reader = jacksonObjectMapper()
.readerFor(FailingDto::class.java)
.with(InjectableValues.Std(injectValues))
.readValue<FailingDto>("{}")
val result = reader.readValue<FailingDto>("{}")

// fixed
// assertNotEquals(result, expected, "GitHubXXX fixed.")
assertEquals(expected, result)
}

Expand All @@ -56,10 +56,10 @@ class Github722 {

@Test
fun withoutDefaultValue() {
val kotlinMapper = jacksonObjectMapper()
val result = kotlinMapper.readerFor(WithoutDefaultValue::class.java)
val reader = jacksonObjectMapper()
.readerFor(WithoutDefaultValue::class.java)
.with(InjectableValues.Std(injectValues))
.readValue<WithoutDefaultValue>("{}")
val result = reader.readValue<WithoutDefaultValue>("{}")

// If there is no default value, the problem does not occur.
assertEquals(WithoutDefaultValue(1, 2), result)
Expand Down