Skip to content

Commit 0b18f12

Browse files
committed
Merge remote-tracking branch 'FasterXML/2.13' into refactor-KVI
2 parents 986e7a6 + 9cd05ee commit 0b18f12

File tree

16 files changed

+492
-47
lines changed

16 files changed

+492
-47
lines changed

pom.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
<parent>
99
<groupId>com.fasterxml.jackson</groupId>
1010
<artifactId>jackson-base</artifactId>
11-
<version>2.13.1-SNAPSHOT</version>
11+
<version>2.13.2-SNAPSHOT</version>
1212
</parent>
1313
<groupId>com.fasterxml.jackson.module</groupId>
1414
<artifactId>jackson-module-kotlin</artifactId>
1515
<name>jackson-module-kotlin</name>
16-
<version>2.13.1-SNAPSHOT</version>
16+
<version>2.13.2-SNAPSHOT</version>
1717
<packaging>bundle</packaging>
1818
<description>Add-on module for Jackson (https://github.com/FasterXML/jackson/) to support
1919
Kotlin language, specifically introspection of method/constructor parameter names,
@@ -204,6 +204,10 @@
204204
<breakBuildOnBinaryIncompatibleModifications>true</breakBuildOnBinaryIncompatibleModifications>
205205
<breakBuildOnSourceIncompatibleModifications>true</breakBuildOnSourceIncompatibleModifications>
206206
<excludes>
207+
<!--
208+
TODO Remove after release of 2.14 and update the oldVersion above to 2.14.
209+
-->
210+
<exclude>com.fasterxml.jackson.module.kotlin.ValueClassBoxSerializer</exclude>
207211
</excludes>
208212
</parameter>
209213
</configuration>

release-notes/CREDITS-2.x

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Kotlin module, version 2.x
44

55
Authors:
66

7-
Jayson Minard/@apatrida, jayson.minard@gmail.com: author
7+
Jayson Minard/@apatrida, jayson.minard@gmail.com: original author
88

99
Tatu Saloranta/@cowtowncoder (tatu.saloranta@iki.fi) : co-author
1010

@@ -13,125 +13,121 @@ Authors:
1313

1414
Contributors:
1515

16+
# 2.13.NEXT
17+
18+
# 2.13.1
19+
20+
Stefan Schmid (schmist@github)
21+
* #519: Contributed test for #518 (null should deserialize to _the_ Unit instance)
22+
1623
wrongwrong (k163377@github)
1724
* #456: Refactor KNAI.findImplicitPropertyName()
1825
* #449: Refactor AnnotatedMethod.hasRequiredMarker()
19-
(2.13.NEXT)
26+
* #521: Fixed lookup of instantiators
27+
* #527: Improvements to serialization of `value class`.
2028

2129
Dmitri Domanine (novtor@github)
2230
* Contributed fix for #490: Missing value of type JsonNode? is deserialized as NullNode instead of null
23-
(2.13.NEXT)
31+
32+
# 2.13.0
2433

2534
Fedor Bobin (Fuud@github)
2635
* #496, #45: Fix treeToValue extension function should not have type erasure
27-
(2.13)
2836

2937
Mikhael Sokolov (sokomishalov@github)
3038
* #489: JsonNode, ArrayNode and ObjectNode extension functions
31-
(2.13)
3239

3340
Max Wiechmann (MaxMello@github)
3441
* #494: ProGuard ProTips in the README
35-
(2.13)
3642

3743
Róbert Papp (TWiStErRob@github)
3844
* #477: KotlinFeature documentation & deprecation replacements
39-
(2.13)
4045

4146
wrongwrong (k163377@github)
4247
* #468: Improved support for value classes
43-
(2.13)
4448

4549
wrongwrong (k163377@github)
4650
* #460: Test for GitHub #451 (`-` in property name handling)
47-
(2.13)
4851

4952
wrongwrong (k163377@github)
5053
* #447: Fix edge case when dealing with sealed classes
51-
(2.13)
5254

5355
wrongwrong (k163377@github)
5456
* Contributed #438: Fixed mapping failure when `private` `companion object` is named
55-
(2.13)
57+
58+
# 2.12.5
5659

5760
Marshall Pierce (marshallpierce@github)
5861
* #474: Reported disrespect for @JsonProperty on parent class
59-
(2.12.5)
6062

6163
Christopher Mason (masoncj@github)
6264
* #194: Contributed test case for @JsonIdentityInfo usage
63-
(2.12.5)
6465

6566
Martin Häusler (MartinHaeusler@github)
6667
* Reported #194: @JsonIdentityInfo bug
67-
(2.12.5)
68+
69+
# 2.12.2
6870

6971
Eric Fenderbosch (efenderbosch@github)
7072
* Fixed #182: Serialize unsigned numbers
71-
(2.12.2)
7273

7374
Elisha Peterson (triathematician@github)
7475
* Reported #409: `module-info.java` missing "exports"
75-
(2.12.2)
76+
77+
# 2.12.1
7678

7779
Wolfgang Jung (elektro-wolle@github)
7880
* Fixed inline class serialization
79-
(2.12.1)
81+
82+
# 2.12.0
8083

8184
John Flynn (Neuman968@github)
8285
* Contributed extension methods for SimpleModule to add serializer and deserializer
8386
extension functions for KClass #322
84-
(2.12.0)
8587

8688
Mateusz Stefek (MateuszStefek@github)
8789
* Reported #321: Make MissingKotlinParameterException a descendant of MismatchedInputException
88-
(2.12.0)
8990

9091
Hideaki Tanabe (tanabe@github)
9192
* Brought README.md into the modern world of Gradle (compile -> implementation)
92-
(2.12.0)
9393

9494
Hidde Wieringa (hiddewie@github)
9595
* Contributed test case for issue 308
9696
* Contributed Kotlin DSL constructor
97-
(2.12.0)
9897

9998
David Riggleman (DavidRigglemanININ@github)
10099
* Wrote strict null checking for collection values
101-
(2.12.0)
100+
101+
# 2.11.0
102102

103103
Drew Stephens (dinomite@github)
104104
* Contributed fix for #281: KotlinObjectSingletonDeserializer fails to deserialize
105105
previously serialized JSON as it doesn't delegate deserializeWithType
106-
(2.11.0)
106+
107+
# 2.10.2
107108

108109
Patrick Strawderman (kilink@github)
109110
* Reported #279: 2.10 introduces another binary compatibility issue in `KotlinModule`
110111
constructor
111-
(2.10.2)
112112

113113
Vladimir Petrakovich (frost13it@github)
114114
* Contributed fix for #279: 2.10 introduces another binary compatibility issue in
115115
`KotlinModule` constructor
116-
(2.10.2)
116+
117+
# 2.10.1
117118

118119
Stéphane B (StephaneBg@github)
119120
* Submitted fix for #176: Version 2.9.7 breaks compatibility with Android minSdk < 24
120-
(2.10.1)
121121

122122
Alain Lehmann (ciderale@github)
123123
* Contributed fix for #225: Don't instantiate new instances of Kotlin singleton objects
124-
(2.10.1)
125124

126125
Andrey Lipatov (LipatovAndrey@github)
127126
* Contributed fix for #80: Boolean property name starting with 'is' not serialized /
128127
deserialized properly
129-
(2.10.1)
130128

131129
Konstantin Volivach (kostya05983@github)
132130
* Contributed fix for #254: Add serializers for Sequences
133-
(2.10.1)
134131

135132
Laimonas Turauskas (Laimiux@github)
136133
* Contributed fix for #180: handle nullable method parameters correctly (for creator methods)
137-
(2.10.1)

release-notes/VERSION-2.x

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,36 @@ Co-maintainers:
1818

1919
No changes since 2.13
2020

21+
2.13.1 (19-Dec-2021)
22+
23+
* #456: Refactor KNAI.findImplicitPropertyName()
24+
(contributed by wrongwrong)
25+
* #449: Refactor AnnotatedMethod.hasRequiredMarker()
26+
(contributed by wrongwrong)
27+
* #521: Fixed lookup of instantiators
28+
(contributed by wrongwrong)
29+
30+
Dmitri Domanine (novtor@github)
31+
* Contributed fix for #490: Missing value of type JsonNode? is deserialized as NullNode instead of null
32+
2133
2.13.0 (30-Sep-2021)
2234

2335
#438: Fixed mapping failure when `private` `companion object` is named
2436
(reported, fix contributed by k163377@github)
25-
37+
#447: Fix edge case when dealing with sealed classes
38+
#468: Improved support for value classes
39+
#477: Improved documentation for KotlinFeature
40+
#489: Extension functions for JsonNode, ArrayNode and ObjectNode
41+
#490: Fix deserialization of missing value (was `NullNode`, now literal `null`)
42+
#494: Improved documentation for ProGuard users
43+
#496: Fix type erasure in treeToValue() extension function
44+
45+
2.12.6 (15-Dec-2021)
2646
2.12.5 (27-Aug-2021)
2747
2.12.4 (06-Jul-2021)
2848
2.12.3 (12-Apr-2021)
2949

30-
No changes since 2.12.2
50+
No recorded changes since 2.12.2
3151

3252
2.12.2 (03-Mar-2021)
3353

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinAnnotationIntrospector.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import java.lang.reflect.AccessibleObject
1111
import java.lang.reflect.Constructor
1212
import java.lang.reflect.Field
1313
import java.lang.reflect.Method
14+
import kotlin.reflect.KClass
1415
import kotlin.reflect.KFunction
1516
import kotlin.reflect.KMutableProperty1
1617
import kotlin.reflect.KProperty1
1718
import kotlin.reflect.KType
1819
import kotlin.reflect.full.createType
1920
import kotlin.reflect.full.declaredMemberProperties
21+
import kotlin.reflect.full.memberProperties
2022
import kotlin.reflect.jvm.*
2123

2224

@@ -59,6 +61,43 @@ internal class KotlinAnnotationIntrospector(private val context: Module.SetupCon
5961
return super.findCreatorAnnotation(config, a)
6062
}
6163

64+
// Find a serializer to handle the case where the getter returns an unboxed value from the value class.
65+
override fun findSerializer(am: Annotated): ValueClassBoxSerializer<*>? = when (am) {
66+
is AnnotatedMethod -> {
67+
val getter = am.member.apply {
68+
// If the return value of the getter is a value class,
69+
// it will be serialized properly without doing anything.
70+
if (this.returnType.isUnboxableValueClass()) return null
71+
}
72+
73+
val kotlinProperty = getter
74+
.declaringClass
75+
.kotlin
76+
.let {
77+
// KotlinReflectionInternalError is raised in GitHub167 test,
78+
// but it looks like an edge case, so it is ignored.
79+
try {
80+
it.memberProperties
81+
} catch (e: Error) {
82+
null
83+
}
84+
}?.find { it.javaGetter == getter }
85+
86+
(kotlinProperty?.returnType?.classifier as? KClass<*>)
87+
?.takeIf { it.isValue }
88+
?.java
89+
?.let { outerClazz ->
90+
@Suppress("UNCHECKED_CAST")
91+
ValueClassBoxSerializer(outerClazz, getter.returnType)
92+
}
93+
}
94+
// Ignore the case of AnnotatedField, because JvmField cannot be set in the field of value class.
95+
else -> null
96+
}
97+
98+
// Perform proper serialization even if the value wrapped by the value class is null.
99+
override fun findNullSerializer(am: Annotated) = findSerializer(am)
100+
62101
/**
63102
* Subclasses can be detected automatically for sealed classes, since all possible subclasses are known
64103
* at compile-time to Kotlin. This makes [com.fasterxml.jackson.annotation.JsonSubTypes] redundant.

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinDeserializers.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@file:Suppress("EXPERIMENTAL_API_USAGE")
2-
31
package com.fasterxml.jackson.module.kotlin
42

53
import com.fasterxml.jackson.core.JsonParser
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.fasterxml.jackson.module.kotlin
2+
3+
import com.fasterxml.jackson.core.JsonToken
4+
import com.fasterxml.jackson.core.exc.InputCoercionException
5+
import com.fasterxml.jackson.databind.*
6+
import com.fasterxml.jackson.databind.deser.std.StdKeyDeserializer
7+
import com.fasterxml.jackson.databind.deser.std.StdKeyDeserializers
8+
9+
// The reason why key is treated as nullable is to match the tentative behavior of StdKeyDeserializer.
10+
// If StdKeyDeserializer is modified, need to modify this too.
11+
12+
internal object UByteKeyDeserializer : StdKeyDeserializer(TYPE_SHORT, UByte::class.java) {
13+
override fun deserializeKey(key: String?, ctxt: DeserializationContext): UByte? = super.deserializeKey(key, ctxt)
14+
?.let {
15+
(it as Short).asUByte() ?: throw InputCoercionException(
16+
null,
17+
"Numeric value (${key}) out of range of UByte (0 - ${UByte.MAX_VALUE}).",
18+
JsonToken.VALUE_NUMBER_INT,
19+
UByte::class.java
20+
)
21+
}
22+
}
23+
24+
internal object UShortKeyDeserializer : StdKeyDeserializer(TYPE_INT, UShort::class.java) {
25+
override fun deserializeKey(key: String?, ctxt: DeserializationContext): UShort? = super.deserializeKey(key, ctxt)
26+
?.let {
27+
(it as Int).asUShort() ?: throw InputCoercionException(
28+
null,
29+
"Numeric value (${key}) out of range of UShort (0 - ${UShort.MAX_VALUE}).",
30+
JsonToken.VALUE_NUMBER_INT,
31+
UShort::class.java
32+
)
33+
}
34+
}
35+
36+
internal object UIntKeyDeserializer : StdKeyDeserializer(TYPE_LONG, UInt::class.java) {
37+
override fun deserializeKey(key: String?, ctxt: DeserializationContext): UInt? = super.deserializeKey(key, ctxt)
38+
?.let {
39+
(it as Long).asUInt() ?: throw InputCoercionException(
40+
null,
41+
"Numeric value (${key}) out of range of UInt (0 - ${UInt.MAX_VALUE}).",
42+
JsonToken.VALUE_NUMBER_INT,
43+
UInt::class.java
44+
)
45+
}
46+
}
47+
48+
// kind parameter is dummy.
49+
internal object ULongKeyDeserializer : StdKeyDeserializer(TYPE_LONG, ULong::class.java) {
50+
override fun deserializeKey(key: String?, ctxt: DeserializationContext): ULong? = key?.let {
51+
it.toBigInteger().asULong() ?: throw InputCoercionException(
52+
null,
53+
"Numeric value (${key}) out of range of ULong (0 - ${ULong.MAX_VALUE}).",
54+
JsonToken.VALUE_NUMBER_INT,
55+
ULong::class.java
56+
)
57+
}
58+
}
59+
60+
internal object KotlinKeyDeserializers : StdKeyDeserializers() {
61+
override fun findKeyDeserializer(
62+
type: JavaType,
63+
config: DeserializationConfig?,
64+
beanDesc: BeanDescription?
65+
): KeyDeserializer? = when (type.rawClass) {
66+
UByte::class.java -> UByteKeyDeserializer
67+
UShort::class.java -> UShortKeyDeserializer
68+
UInt::class.java -> UIntKeyDeserializer
69+
ULong::class.java -> ULongKeyDeserializer
70+
else -> null
71+
}
72+
}

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModule.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class KotlinModule @Deprecated(
122122
context.appendAnnotationIntrospector(KotlinNamesAnnotationIntrospector(this, cache, ignoredClassesForImplyingJsonCreator))
123123

124124
context.addDeserializers(KotlinDeserializers())
125+
context.addKeyDeserializers(KotlinKeyDeserializers)
125126
context.addSerializers(KotlinSerializers())
126127
context.addKeySerializers(KotlinKeySerializers())
127128

0 commit comments

Comments
 (0)