Skip to content

Commit

Permalink
Merge remote-tracking branch 'FasterXML/2.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
k163377 committed Dec 9, 2023
2 parents 9beb514 + cf890c6 commit b2d77c3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
fail-fast: false
matrix:
java_version: ['8', '11', '17', '21']
kotlin_version: ['1.6.21', '1.7.20', '1.8.22', '1.9.0']
kotlin_version: ['1.7.22', '1.8.22', '1.9.21']
os: ['ubuntu-20.04']
env:
JAVA_OPTS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,14 @@ println(arrayNode.toString()) // ["foo",true,1,1.0,"YmFy"]
Different `kotlin-core` versions are supported by different Jackson Kotlin module minor versions.
Here is an incomplete list of supported versions:

* Jackson 2.17.x: Kotlin-core 1.7 - 2.0
* Jackson 2.16.x: Kotlin-core 1.6 - 1.9
* Jackson 2.15.x: Kotlin-core 1.5 - 1.8
* Jackson 2.14.x: Kotlin-core 1.4 - 1.8
* Jackson 2.13.x: Kotlin-core 1.4 - 1.7

Please note that the versions supported by 2.17 are tentative and may change depending on the release date.

## Android
Supported Android SDK versions are determined by `jackson-databind`.
Please see [this link](https://github.com/FasterXML/jackson-databind#android) for details.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.kotlin>1.6.21</version.kotlin>
<version.kotlin>1.7.22</version.kotlin>

<!-- Generate PackageVersion.java into this directory. -->
<packageVersion.dir>tools/jackson/module/kotlin</packageVersion.dir>
Expand Down
1 change: 1 addition & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Contributors:
# 2.17.0 (not yet released)

WrongWrong (@k163377)
* #738: Fix JacksonInject priority.
* #732: SequenceSerializer removed.
* #727: Fixed overriding findCreatorAnnotation instead of hasCreatorAnnotation

Expand Down
1 change: 1 addition & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Co-maintainers:

2.17.0 (not yet released)

#738: JacksonInject is now preferred over the default argument(fixes #722).
#732: SequenceSerializer removed.
#727: Fixed overriding findCreatorAnnotation instead of hasCreatorAnnotation.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import tools.jackson.databind.deser.ValueInstantiators
import tools.jackson.databind.deser.bean.PropertyValueBuffer
import tools.jackson.databind.deser.impl.NullsAsEmptyProvider
import tools.jackson.databind.deser.std.StdValueInstantiator
import tools.jackson.databind.exc.MismatchedInputException
import java.lang.reflect.TypeVariable
import kotlin.reflect.KParameter
import kotlin.reflect.KType
Expand Down Expand Up @@ -67,24 +66,20 @@ internal class KotlinValueInstantiator(
val jsonProp = props[idx]
val isMissing = !buffer.hasParameter(jsonProp)

if (isMissing && paramDef.isOptional) {
return@forEachIndexed
}

val paramType = paramDef.type
var paramVal = if (!isMissing || paramDef.isPrimitive() || jsonProp.hasInjectableValueId()) {
var paramVal = if (!isMissing || jsonProp.hasInjectableValueId()) {
val tempParamVal = buffer.getParameter(jsonProp)
if (tempParamVal == null && jsonProp.skipNulls() && paramDef.isOptional) {
return@forEachIndexed
}
tempParamVal
} else {
if (paramType.isMarkedNullable) {
when {
paramDef.isOptional -> return@forEachIndexed
// do not try to create any object if it is nullable and the value is missing
null
} else {
paramType.isMarkedNullable -> null
// to get suitable "missing" value provided by deserializer
jsonProp.valueDeserializer?.getAbsentValue(ctxt)
else -> jsonProp.valueDeserializer?.getAbsentValue(ctxt)
}
}

Expand Down Expand Up @@ -157,13 +152,6 @@ internal class KotlinValueInstantiator(

}

private fun KParameter.isPrimitive(): Boolean {
return when (val javaType = type.javaType) {
is Class<*> -> javaType.isPrimitive
else -> false
}
}

private fun SettableBeanProperty.hasInjectableValueId(): Boolean = injectableValueId != null
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package tools.jackson.module.kotlin.test

import junit.framework.TestCase.assertEquals
import org.junit.Assert.assertThrows
import tools.jackson.databind.DeserializationFeature
import tools.jackson.databind.exc.MismatchedInputException
import tools.jackson.module.kotlin.jacksonMapperBuilder
import tools.jackson.module.kotlin.readValue
import kotlin.test.Test

class FailNullForPrimitiveTest {
data class Dto(
val foo: Int,
val bar: Int?
)

@Test
fun test() {
val mapper = jacksonMapperBuilder()
.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true)
.build()

assertThrows(MismatchedInputException::class.java) {
mapper.readValue<Dto>("{}")
}

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

assertEquals(Dto(0, null), mapper.readValue<Dto>("""{"foo":0}"""))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import tools.jackson.databind.ObjectMapper
import tools.jackson.module.kotlin.jacksonObjectMapper
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals

class Github722 {
data class FailingDto @JsonCreator constructor(
Expand Down Expand Up @@ -43,8 +42,7 @@ class Github722 {
.with(InjectableValues.Std(injectValues))
.readValue<FailingDto>("{}")

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

data class WithoutDefaultValue(
Expand Down

0 comments on commit b2d77c3

Please sign in to comment.