Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5aac759
Update kogera version
k163377 Jun 14, 2025
18328a5
Merge pull request #357 from ProjectMapK/k163377-patch-1
k163377 Jun 14, 2025
13429c0
Add exhaustive tests for JsonValue usage in value class
k163377 Jun 15, 2025
cc1b397
Add exhaustive tests for JsonKey usage in value class
k163377 Jun 15, 2025
2ac2a31
Remove unused import
k163377 Jun 15, 2025
54a7bc9
Merge pull request #358 from ProjectMapK/json-value-json-key-test
k163377 Jun 15, 2025
cb8296a
Add guidelines for junie
k163377 Jun 15, 2025
63c46c9
Merge pull request #359 from ProjectMapK/junie
k163377 Jun 15, 2025
1a37a09
Update test-main.yml
k163377 Jun 15, 2025
627df7a
Merge pull request #360 from ProjectMapK/k163377-patch-1
k163377 Jun 15, 2025
953450f
Update test-main.yml
k163377 Jun 15, 2025
416f6ed
Merge pull request #361 from ProjectMapK/k163377-patch-1
k163377 Jun 15, 2025
1d3cf2a
Bump the dependencies group with 5 updates
dependabot[bot] Jun 20, 2025
50281a2
Merge pull request #362 from ProjectMapK/dependabot/gradle/dependenci…
k163377 Jun 21, 2025
890214d
Porting test
k163377 Jun 21, 2025
3dd424f
Merge pull request #363 from ProjectMapK/porting-test
k163377 Jun 21, 2025
1022843
Bump the dependencies group with 2 updates
dependabot[bot] Jun 27, 2025
6610368
Merge pull request #364 from ProjectMapK/dependabot/gradle/dependenci…
k163377 Jun 27, 2025
ec592fa
Modified to use more optimized concrete converter
k163377 Jul 5, 2025
0cdfc8b
Merge pull request #365 from ProjectMapK/fix/dc
k163377 Jul 5, 2025
8b17741
Update Kotlin versions on CI
k163377 Jul 5, 2025
0a6ec91
Merge pull request #366 from ProjectMapK/ci
k163377 Jul 5, 2025
b632241
Change MethodType constants to lazy
k163377 Jul 6, 2025
119da0d
Merge pull request #367 from ProjectMapK/fix/lazy
k163377 Jul 6, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/test-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
# LTS versions, latest version (if exists)
java-version: [ '17', '21', '24' ]
# Minimum version, latest release version, latest pre-release version (if exists)
kotlin: ['2.0.21', '2.1.20', '2.2.0-RC']
kotlin: ['2.0.21', '2.1.21', '2.2.0']
env:
KOTLIN_VERSION: ${{ matrix.kotlin }}
name: "Kotlin ${{ matrix.kotlin }} - Java ${{ matrix.java-version }}"
Expand Down
6 changes: 6 additions & 0 deletions .junie/guidelines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Spring Boot
## 1. Perform formatting just before completing the task

```bash
./gradlew formatKotlin
```
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ val jacksonVersion = libs.versions.jackson.get()
val generatedSrcPath = "${layout.buildDirectory.get()}/generated/kotlin"

group = groupStr
version = "${jacksonVersion}-beta25"
version = "${jacksonVersion}-beta26"

repositories {
mavenCentral()
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[versions]
kotlin = "2.0.21" # Mainly for CI, it can be rewritten by environment variable.
jackson = "2.19.0"
jackson = "2.19.1"

# test libs
junit = "5.13.1"
junit = "5.13.2"

[libraries]
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib" }
Expand All @@ -14,7 +14,7 @@ jackson-annotations = { module = "com.fasterxml.jackson.core:jackson-annotations
# test libs
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect" }
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
mockk = "io.mockk:mockk:1.14.2"
mockk = "io.mockk:mockk:1.14.4"
jackson-xml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-xml", version.ref = "jackson" }
jackson-csv = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-csv", 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 @@ -71,15 +71,15 @@ internal val STRING_CLASS = String::class.java
internal val JAVA_UUID_CLASS = java.util.UUID::class.java
internal val ANY_CLASS = Any::class.java

internal val ANY_TO_ANY_METHOD_TYPE = MethodType.methodType(ANY_CLASS, ANY_CLASS)
internal val ANY_TO_INT_METHOD_TYPE = MethodType.methodType(INT_CLASS, ANY_CLASS)
internal val ANY_TO_LONG_METHOD_TYPE = MethodType.methodType(LONG_CLASS, ANY_CLASS)
internal val ANY_TO_STRING_METHOD_TYPE = MethodType.methodType(STRING_CLASS, ANY_CLASS)
internal val ANY_TO_JAVA_UUID_METHOD_TYPE = MethodType.methodType(JAVA_UUID_CLASS, ANY_CLASS)
internal val INT_TO_ANY_METHOD_TYPE = MethodType.methodType(ANY_CLASS, INT_CLASS)
internal val LONG_TO_ANY_METHOD_TYPE = MethodType.methodType(ANY_CLASS, LONG_CLASS)
internal val STRING_TO_ANY_METHOD_TYPE = MethodType.methodType(ANY_CLASS, STRING_CLASS)
internal val JAVA_UUID_TO_ANY_METHOD_TYPE = MethodType.methodType(ANY_CLASS, JAVA_UUID_CLASS)
internal val ANY_TO_ANY_METHOD_TYPE by lazy { MethodType.methodType(ANY_CLASS, ANY_CLASS) }
internal val ANY_TO_INT_METHOD_TYPE by lazy { MethodType.methodType(INT_CLASS, ANY_CLASS) }
internal val ANY_TO_LONG_METHOD_TYPE by lazy { MethodType.methodType(LONG_CLASS, ANY_CLASS) }
internal val ANY_TO_STRING_METHOD_TYPE by lazy { MethodType.methodType(STRING_CLASS, ANY_CLASS) }
internal val ANY_TO_JAVA_UUID_METHOD_TYPE by lazy { MethodType.methodType(JAVA_UUID_CLASS, ANY_CLASS) }
internal val INT_TO_ANY_METHOD_TYPE by lazy { MethodType.methodType(ANY_CLASS, INT_CLASS) }
internal val LONG_TO_ANY_METHOD_TYPE by lazy { MethodType.methodType(ANY_CLASS, LONG_CLASS) }
internal val STRING_TO_ANY_METHOD_TYPE by lazy { MethodType.methodType(ANY_CLASS, STRING_CLASS) }
internal val JAVA_UUID_TO_ANY_METHOD_TYPE by lazy { MethodType.methodType(ANY_CLASS, JAVA_UUID_CLASS) }

internal fun unreflect(method: Method): MethodHandle = MethodHandles.lookup().unreflect(method)
internal fun unreflectAsType(method: Method, type: MethodType): MethodHandle = unreflect(method).asType(type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package io.github.projectmapk.jackson.module.kogera.ser
import com.fasterxml.jackson.databind.JavaType
import com.fasterxml.jackson.databind.type.TypeFactory
import com.fasterxml.jackson.databind.util.StdConverter
import io.github.projectmapk.jackson.module.kogera.GenericValueClassBoxConverter
import io.github.projectmapk.jackson.module.kogera.JavaDuration
import io.github.projectmapk.jackson.module.kogera.KOTLIN_DURATION_CLASS
import io.github.projectmapk.jackson.module.kogera.KotlinDuration
import io.github.projectmapk.jackson.module.kogera.LongValueClassBoxConverter
import kotlin.time.toJavaDuration

internal class SequenceToIteratorConverter(private val input: JavaType) : StdConverter<Sequence<*>, Iterator<*>>() {
Expand All @@ -21,7 +21,7 @@ internal class SequenceToIteratorConverter(private val input: JavaType) : StdCon
}

internal object KotlinDurationValueToJavaDurationConverter : StdConverter<Long, JavaDuration>() {
private val boxConverter by lazy { GenericValueClassBoxConverter(Long::class.java, KOTLIN_DURATION_CLASS) }
private val boxConverter by lazy { LongValueClassBoxConverter(KOTLIN_DURATION_CLASS) }

override fun convert(value: Long): JavaDuration = KotlinToJavaDurationConverter.convert(boxConverter.convert(value))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.projectmapk.jackson.module.kogera.zIntegration.ser.valueClass.jsonKey

import com.fasterxml.jackson.annotation.JsonKey
import io.github.projectmapk.jackson.module.kogera.defaultMapper
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class NonNullObjectTest {
@JvmInline
value class NonNull(val v: String) {
@JsonKey
fun jsonValue() = v + "_modified"
}

@Test
fun nonNullTest() {
assertEquals(
"""{"test_modified":null}""",
defaultMapper.writeValueAsString(mapOf(NonNull("test") to null)),
)
}

@JvmInline
value class Nullable(val v: String) {
@JsonKey
fun jsonValue() = v.takeIf { it.length % 2 == 0 }?.let { it + "_modified" }
}

// The case of returning null as a key is unnecessary because it will result in an error
@Test
fun nullableTest() {
assertEquals(
"""{"test_modified":null}""",
defaultMapper.writeValueAsString(mapOf(Nullable("test") to null)),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.projectmapk.jackson.module.kogera.zIntegration.ser.valueClass.jsonKey

import com.fasterxml.jackson.annotation.JsonKey
import io.github.projectmapk.jackson.module.kogera.defaultMapper
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class NullableObjectTest {
@JvmInline
value class Value(val v: String?) {
@JsonKey
fun jsonValue() = v?.let { it + "_modified" }
}

// The case of returning null as a key is unnecessary because it will result in an error
@Test
fun test() {
assertEquals(
"""{"test_modified":null}""",
defaultMapper.writeValueAsString(mapOf(Value("test") to null)),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.projectmapk.jackson.module.kogera.zIntegration.ser.valueClass.jsonKey

import com.fasterxml.jackson.annotation.JsonKey
import io.github.projectmapk.jackson.module.kogera.defaultMapper
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class NullablePrimitiveTest {
@JvmInline
value class Value(val v: Int?) {
@JsonKey
fun jsonValue() = v?.let { it + 100 }
}

// The case of returning null as a key is unnecessary because it will result in an error
@Test
fun test() {
assertEquals(
"""{"100":null}""",
defaultMapper.writeValueAsString(mapOf(Value(0) to null)),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.projectmapk.jackson.module.kogera.zIntegration.ser.valueClass.jsonKey

import com.fasterxml.jackson.annotation.JsonKey
import io.github.projectmapk.jackson.module.kogera.defaultMapper
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class PrimitiveTest {
@JvmInline
value class NonNull(val v: Int) {
@JsonKey
fun jsonValue() = v + 100
}

@Test
fun nonNullTest() {
assertEquals(
"""{"100":null}""",
defaultMapper.writeValueAsString(mapOf(NonNull(0) to null)),
)
}

@JvmInline
value class Nullable(val v: Int) {
@JsonKey
fun jsonValue() = v.takeIf { it % 2 == 0 }?.let { it + 100 }
}

// The case of returning null as a key is unnecessary because it will result in an error
@Test
fun nullableTest() {
assertEquals(
"""{"100":null}""",
defaultMapper.writeValueAsString(mapOf(Nullable(0) to null)),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.projectmapk.jackson.module.kogera.zIntegration.ser.valueClass.jsonKey

import com.fasterxml.jackson.annotation.JsonKey
import io.github.projectmapk.jackson.module.kogera.defaultMapper
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class TwoUnitPrimitiveTest {
@JvmInline
value class NonNull(val v: Long) {
@JsonKey
fun jsonValue() = v + 100
}

@Test
fun nonNullTest() {
assertEquals(
"""{"100":null}""",
defaultMapper.writeValueAsString(mapOf(NonNull(0) to null)),
)
}

@JvmInline
value class Nullable(val v: Long) {
@JsonKey
fun jsonValue() = v.takeIf { it % 2L == 0L }?.let { it + 100 }
}

// The case of returning null as a key is unnecessary because it will result in an error
@Test
fun nullableTest() {
assertEquals(
"""{"100":null}""",
defaultMapper.writeValueAsString(mapOf(Nullable(0) to null)),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package io.github.projectmapk.jackson.module.kogera.zIntegration.ser.valueClass.jsonValue

import com.fasterxml.jackson.annotation.JsonValue
import io.github.projectmapk.jackson.module.kogera.defaultMapper
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test

class NonNullObjectTest {
@JvmInline
value class NonNull(val v: String) {
@JsonValue
fun jsonValue() = v + "_modified"
}

data class NonNullDto(val v: NonNull)

@Nested
inner class NonNullTest {
@Test
fun direct() {
assertEquals(
"\"test_modified\"",
defaultMapper.writeValueAsString(NonNull("test")),
)
}

@Test
fun asProperty() {
assertEquals(
"""{"v":"test_modified"}""",
defaultMapper.writeValueAsString(NonNullDto(NonNull("test"))),
)
}
}

@JvmInline
value class Nullable(val v: String) {
@JsonValue
fun jsonValue() = v.takeIf { it.length % 2 == 0 }?.let { it + "_modified" }
}

data class NullableDto(val v: Nullable)

@Nested
inner class NullableTest {
@Nested
inner class DirectTest {
@Test
fun nonNull() {
assertEquals(
"\"even_modified\"",
defaultMapper.writeValueAsString(Nullable("even")),
)
}

@Test
fun `null`() {
assertEquals(
"null",
defaultMapper.writeValueAsString(Nullable("odd")),
)
}
}

@Nested
inner class AsPropertyTest {
@Test
fun nonNull() {
assertEquals(
"""{"v":"even_modified"}""",
defaultMapper.writeValueAsString(NullableDto(Nullable("even"))),
)
}

@Test
fun `null`() {
assertEquals(
"""{"v":null}""",
defaultMapper.writeValueAsString(NullableDto(Nullable("odd"))),
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.github.projectmapk.jackson.module.kogera.zIntegration.ser.valueClass.jsonValue

import com.fasterxml.jackson.annotation.JsonValue
import io.github.projectmapk.jackson.module.kogera.defaultMapper
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test

class NullableObjectTest {
@JvmInline
value class Value(val v: String?) {
@JsonValue
fun jsonValue() = v?.let { it + "_modified" }
}

@Nested
inner class DirectTest {
@Test
fun nonNull() {
assertEquals(
"\"test_modified\"",
defaultMapper.writeValueAsString(Value("test")),
)
}

@Test
fun `null`() {
assertEquals(
"null",
defaultMapper.writeValueAsString(Value(null)),
)
}
}

data class Dto(val v: Value)

@Nested
inner class AsPropertyTest {
@Test
fun nonNull() {
assertEquals(
"""{"v":"test_modified"}""",
defaultMapper.writeValueAsString(Dto(Value("test"))),
)
}

@Test
fun `null`() {
assertEquals(
"""{"v":null}""",
defaultMapper.writeValueAsString(Dto(Value(null))),
)
}
}
}
Loading
Loading