Skip to content

Commit

Permalink
Merge pull request #257 from ProjectMapK/develop
Browse files Browse the repository at this point in the history
Release 2024-12-29 11:02:56 +0000
  • Loading branch information
k163377 authored Dec 29, 2024
2 parents bd35bb8 + 87ad105 commit 8dd6e22
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 28 deletions.
25 changes: 25 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2

updates:
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "weekly"
# Friday 19:00 JST
day: "saturday"
time: "04:00"
groups:
dependencies:
patterns:
- "*"
ignore:
# The version of Kotlin is fixed to the lowest, so it is not subject to automatic updates
- dependency-name: "kotlin"
- dependency-name: "kotlinx-metadata-jvm"
# linter is not subject to automatic renewal as it will be migrated to detekt in the future
- dependency-name: "org.jmailen.kotlinter"
7 changes: 2 additions & 5 deletions .github/workflows/test-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ jobs:
java-version: [ '8', '11', '17', '21', '23' ]
# Minimum version, latest release version, latest pre-release version (if exists)
kotlin:
- name: '1.8.22'
version: '1.8.22'
k2: false
- name: '1.9.25'
version: '1.9.25'
k2: false
Expand All @@ -53,9 +50,9 @@ jobs:
- name: '2.0.21 K2'
version: '2.0.21'
k2: true
- name: '2.1.0-RC'
- name: '2.1.0-RC2'
k2: false
- name: '2.1.0-RC K2'
- name: '2.1.0-RC2 K2'
k2: true
env:
KOTLIN_VERSION: ${{ matrix.kotlin.version }}
Expand Down
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Details are summarized in [KogeraSpecificImplementations](./docs/KogeraSpecificI
# Compatibility
- `jackson 2.18.x`
- `Java 8+`
- `Kotlin 1.8.22+`
- `Kotlin 1.9.25+`

## About compatibility checks
Compatibility checks for `Java` and `Kotlin` are done by `CI` grid tests.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ val jacksonVersion = libs.versions.jackson.get()
val generatedSrcPath = "${layout.buildDirectory.get()}/generated/kotlin"

group = groupStr
version = "${jacksonVersion}-beta15"
version = "${jacksonVersion}-beta16"

repositories {
mavenCentral()
Expand Down
1 change: 0 additions & 1 deletion docs/FixedIssues.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ A list of issues that have not been resolved in `jackson-module-kotlin`, but hav

## Fixed
- [Getting MismatchedInputException instead of MissingKotlinParameterException · Issue \#234](https://github.com/FasterXML/jackson-module-kotlin/issues/234)
- [Private getter with different return type hides property · Issue \#341](https://github.com/FasterXML/jackson-module-kotlin/issues/341)
- [Remove \`kotlin\-reflect\` and replace it with \`kotlinx\-metadata\-jvm\` · Issue \#450](https://github.com/FasterXML/jackson-module-kotlin/issues/450)
- [Annotation given to constructor parameters containing \`value class\` as argument does not work · Issue \#651](https://github.com/FasterXML/jackson-module-kotlin/issues/651)
- [How to deserialize a kotlin\.ranges\.ClosedRange<T> with Jackson · Issue \#663](https://github.com/FasterXML/jackson-module-kotlin/issues/663)
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[versions]
kotlin = "1.8.22" # Mainly for CI, it can be rewritten by environment variable.
jackson = "2.18.1"
kotlin = "1.9.25" # Mainly for CI, it can be rewritten by environment variable.
jackson = "2.18.2"

# test libs
junit = "5.11.3"
junit = "5.11.4"

[libraries]
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib" }
Expand All @@ -16,7 +16,7 @@ kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect" }
junit-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit" }
junit-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
mockk = "io.mockk:mockk:1.13.13"
mockk = "io.mockk:mockk:1.13.14"
jackson-xml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-xml", version.ref = "jackson" }
jackson-jsr310 = { module = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310", version.ref = "jackson" }

Expand Down
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}"""))
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.projectmapk.jackson.module.kogera.zPorted.test

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.exc.MismatchedInputException
import com.fasterxml.jackson.databind.exc.InvalidNullException
import io.github.projectmapk.jackson.module.kogera.KotlinFeature.StrictNullChecks
import io.github.projectmapk.jackson.module.kogera.kotlinModule
import io.github.projectmapk.jackson.module.kogera.readValue
Expand Down Expand Up @@ -37,7 +37,7 @@ class StrictNullChecksTest {
@Test
fun testListOfInt() {
val json = """{"samples":[1, null]}"""
assertThrows<MismatchedInputException> { mapper.readValue<ClassWithListOfInt>(json) }
assertThrows<InvalidNullException> { mapper.readValue<ClassWithListOfInt>(json) }
}

private data class ClassWithNullableListOfInt(val samples: List<Int>?)
Expand Down Expand Up @@ -65,7 +65,7 @@ class StrictNullChecksTest {
@Test
fun testArrayOfInt() {
val json = """{"samples":[1, null]}"""
assertThrows<MismatchedInputException> { mapper.readValue<ClassWithArrayOfInt>(json) }
assertThrows<InvalidNullException> { mapper.readValue<ClassWithArrayOfInt>(json) }
}

private data class ClassWithNullableArrayOfInt(val samples: Array<Int>?)
Expand Down Expand Up @@ -93,7 +93,7 @@ class StrictNullChecksTest {
@Test
fun testMapOfStringToIntWithNullValue() {
val json = """{ "samples": { "key": null } }"""
assertThrows<MismatchedInputException> { mapper.readValue<ClassWithMapOfStringToInt>(json) }
assertThrows<InvalidNullException> { mapper.readValue<ClassWithMapOfStringToInt>(json) }
}

private data class ClassWithNullableMapOfStringToInt(val samples: Map<String, Int>?)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.github.projectmapk.jackson.module.kogera.zPorted.test.github

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.ObjectMapper
import io.github.projectmapk.jackson.module.kogera.readValue
import io.github.projectmapk.jackson.module.kogera.registerKotlinModule
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class GitHub841 {
object Foo {
override fun toString(): String = "Foo()"

@JvmStatic
@JsonCreator
fun deserialize(): Foo {
return Foo
}
}

private val mapper = ObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_ABSENT)
.registerKotlinModule()

@Test
fun shouldDeserializeSimpleObject() {
val value = Foo
val serialized = mapper.writeValueAsString(value)
val deserialized = mapper.readValue<Foo>(serialized)

assertEquals(value, deserialized)
}
}

0 comments on commit 8dd6e22

Please sign in to comment.