forked from FasterXML/jackson-module-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve: FasterXML#199
- Loading branch information
Showing
4 changed files
with
40 additions
and
3 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
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/fasterxml/jackson/module/kotlin/ReflectJvmMapping.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,16 @@ | ||
package com.fasterxml.jackson.module.kotlin | ||
|
||
import java.lang.reflect.Constructor | ||
import kotlin.reflect.KFunction | ||
import kotlin.reflect.jvm.javaConstructor | ||
|
||
val <T : Any> Constructor<T>.kotlinCtor: KFunction<T>? | ||
get() { | ||
val kotlinClass = declaringClass.kotlin | ||
return if (kotlinClass.isValue) { | ||
val parameterTypes = this.parameters.map { p -> p.type } | ||
kotlinClass.constructors.firstOrNull { it.parameters.map { p -> p.type.erasedType() } == parameterTypes } | ||
} else { | ||
kotlinClass.constructors.firstOrNull { it.javaConstructor == this } | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/ValueClassTest.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,21 @@ | ||
package com.fasterxml.jackson.module.kotlin.test | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.kotlinModule | ||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class ValueClassTest { | ||
@JvmInline | ||
value class TestClass(val foo: List<Int>) | ||
|
||
@Test | ||
fun `test value class`() { | ||
val mapper = createMapper() | ||
Assert.assertEquals(listOf(1, 2), mapper.readValue("""{"foo": [1,2]}""", TestClass::class.java).foo) | ||
} | ||
|
||
private fun createMapper(): ObjectMapper { | ||
return ObjectMapper().registerModule(kotlinModule()) | ||
} | ||
} |