Skip to content

Commit 09ff7c9

Browse files
committed
add formatter and format
1 parent 62383c5 commit 09ff7c9

File tree

80 files changed

+498
-437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+498
-437
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
kotlin("jvm") version "1.7.10"
33
java
4+
id("org.jmailen.kotlinter") version "3.11.1"
45
}
56

67
group = "com.fasterxml.jackson"

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public fun jacksonMapperBuilder(): JsonMapper.Builder = JsonMapper.builder().add
3838

3939
public fun ObjectMapper.registerKotlinModule(): ObjectMapper = this.registerModule(kotlinModule())
4040

41-
public inline fun <reified T> jacksonTypeRef(): TypeReference<T> = object: TypeReference<T>() {}
41+
public inline fun <reified T> jacksonTypeRef(): TypeReference<T> = object : TypeReference<T>() {}
4242

4343
public inline fun <reified T> ObjectMapper.readValue(jp: JsonParser): T = readValue(jp, jacksonTypeRef<T>())
4444
public inline fun <reified T> ObjectMapper.readValues(jp: JsonParser): MappingIterator<T> = readValues(jp, jacksonTypeRef<T>())
@@ -93,14 +93,16 @@ public operator fun JsonNode.contains(field: String): Boolean = has(field)
9393
public operator fun JsonNode.contains(index: Int): Boolean = has(index)
9494

9595
public fun <T : Any> SimpleModule.addSerializer(
96-
kClass: KClass<T>, serializer: JsonSerializer<T>
96+
kClass: KClass<T>,
97+
serializer: JsonSerializer<T>
9798
): SimpleModule = this.apply {
9899
kClass.javaPrimitiveType?.let { addSerializer(it, serializer) }
99100
addSerializer(kClass.javaObjectType, serializer)
100101
}
101102

102103
public fun <T : Any> SimpleModule.addDeserializer(
103-
kClass: KClass<T>, deserializer: JsonDeserializer<T>
104+
kClass: KClass<T>,
105+
deserializer: JsonDeserializer<T>
104106
): SimpleModule = this.apply {
105107
kClass.javaPrimitiveType?.let { addDeserializer(it, deserializer) }
106108
addDeserializer(kClass.javaObjectType, deserializer)

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ import kotlin.reflect.full.declaredMemberProperties
2424
import kotlin.reflect.full.memberProperties
2525
import kotlin.reflect.jvm.*
2626

27-
28-
internal class KotlinAnnotationIntrospector(private val context: Module.SetupContext,
29-
private val cache: ReflectionCache,
30-
private val nullToEmptyCollection: Boolean,
31-
private val nullToEmptyMap: Boolean,
32-
private val nullIsSameAsDefault: Boolean) : NopAnnotationIntrospector() {
27+
internal class KotlinAnnotationIntrospector(
28+
private val context: Module.SetupContext,
29+
private val cache: ReflectionCache,
30+
private val nullToEmptyCollection: Boolean,
31+
private val nullToEmptyMap: Boolean,
32+
private val nullIsSameAsDefault: Boolean
33+
) : NopAnnotationIntrospector() {
3334

3435
// TODO: implement nullIsSameAsDefault flag, which represents when TRUE that if something has a default value, it can be passed a null to default it
3536
// this likely impacts this class to be accurate about what COULD be considered required
@@ -56,7 +57,6 @@ internal class KotlinAnnotationIntrospector(private val context: Module.SetupCon
5657
}
5758

5859
override fun findCreatorAnnotation(config: MapperConfig<*>, a: Annotated): JsonCreator.Mode? {
59-
6060
// TODO: possible work around for JsonValue class that requires the class constructor to have the JsonCreator(Mode.DELEGATED) set?
6161
// since we infer the creator at times for these methods, the wrong mode could be implied.
6262

@@ -93,10 +93,12 @@ internal class KotlinAnnotationIntrospector(private val context: Module.SetupCon
9393
val innerClazz = getter.returnType
9494

9595
ValueClassStaticJsonValueSerializer.createdOrNull(outerClazz, innerClazz)
96-
?: @Suppress("UNCHECKED_CAST") (ValueClassBoxSerializer(
97-
outerClazz,
98-
innerClazz
99-
))
96+
?: @Suppress("UNCHECKED_CAST") (
97+
ValueClassBoxSerializer(
98+
outerClazz,
99+
innerClazz
100+
)
101+
)
100102
}
101103
}
102104
// Ignore the case of AnnotatedField, because JvmField cannot be set in the field of value class.
@@ -121,7 +123,7 @@ internal class KotlinAnnotationIntrospector(private val context: Module.SetupCon
121123

122124
private fun AnnotatedField.hasRequiredMarker(): Boolean? {
123125
val byAnnotation = (member as Field).isRequiredByAnnotation()
124-
val byNullability = (member as Field).kotlinProperty?.returnType?.isRequired()
126+
val byNullability = (member as Field).kotlinProperty?.returnType?.isRequired()
125127

126128
return requiredAnnotationOrNullability(byAnnotation, byNullability)
127129
}
@@ -141,7 +143,7 @@ internal class KotlinAnnotationIntrospector(private val context: Module.SetupCon
141143
}
142144

143145
private fun Method.isRequiredByAnnotation(): Boolean? {
144-
return (this.annotations.firstOrNull { it.annotationClass.java == JsonProperty::class.java } as? JsonProperty)?.required
146+
return (this.annotations.firstOrNull { it.annotationClass.java == JsonProperty::class.java } as? JsonProperty)?.required
145147
}
146148

147149
// Since Kotlin's property has the same Type for each field, getter, and setter,
@@ -183,8 +185,8 @@ internal class KotlinAnnotationIntrospector(private val context: Module.SetupCon
183185

184186
val byNullability = when (member) {
185187
is Constructor<*> -> member.kotlinFunction?.isConstructorParameterRequired(index)
186-
is Method -> member.kotlinFunction?.isMethodParameterRequired(index)
187-
else -> null
188+
is Method -> member.kotlinFunction?.isMethodParameterRequired(index)
189+
else -> null
188190
}
189191

190192
return requiredAnnotationOrNullability(byAnnotation, byNullability)
@@ -195,7 +197,7 @@ internal class KotlinAnnotationIntrospector(private val context: Module.SetupCon
195197
}
196198

197199
private fun KFunction<*>.isMethodParameterRequired(index: Int): Boolean {
198-
return isParameterRequired(index+1)
200+
return isParameterRequired(index + 1)
199201
}
200202

201203
private fun KFunction<*>.isParameterRequired(index: Int): Boolean {
@@ -208,7 +210,7 @@ internal class KotlinAnnotationIntrospector(private val context: Module.SetupCon
208210
}
209211

210212
return !paramType.isMarkedNullable && !param.isOptional &&
211-
!(isPrimitive && !context.isEnabled(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES))
213+
!(isPrimitive && !context.isEnabled(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES))
212214
}
213215

214216
private fun KType.isRequired(): Boolean = !isMarkedNullable

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import com.fasterxml.jackson.annotation.JsonCreator
44
import com.fasterxml.jackson.annotation.JsonIgnore
55
import com.fasterxml.jackson.annotation.JsonProperty
66

7-
internal abstract class ClosedRangeMixin<T> @JsonCreator constructor(public val start: T, @get:JsonProperty("end") public val endInclusive: T) {
8-
@JsonIgnore abstract public fun getEnd(): T
9-
@JsonIgnore abstract public fun getFirst(): T
10-
@JsonIgnore abstract public fun getLast(): T
11-
@JsonIgnore abstract public fun getIncrement(): T
12-
@JsonIgnore abstract public fun isEmpty(): Boolean
13-
@JsonIgnore abstract public fun getStep(): T
7+
internal abstract class ClosedRangeMixin<T> @JsonCreator constructor(public val start: T, @get:JsonProperty("end") public val endInclusive: T) {
8+
@JsonIgnore public abstract fun getEnd(): T
9+
10+
@JsonIgnore public abstract fun getFirst(): T
11+
12+
@JsonIgnore public abstract fun getLast(): T
13+
14+
@JsonIgnore public abstract fun getIncrement(): T
15+
16+
@JsonIgnore public abstract fun isEmpty(): Boolean
17+
18+
@JsonIgnore public abstract fun getStep(): T
1419
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ import java.util.*
1717
import kotlin.reflect.KClass
1818

1919
/**
20-
* @param reflectionCacheSize Default: 512. Size, in items, of the caches used for mapping objects.
21-
* @param nullToEmptyCollection Default: false. Whether to deserialize null values for collection properties as
20+
* @param reflectionCacheSize Default: 512. Size, in items, of the caches used for mapping objects.
21+
* @param nullToEmptyCollection Default: false. Whether to deserialize null values for collection properties as
2222
* empty collections.
23-
* @param nullToEmptyMap Default: false. Whether to deserialize null values for a map property to an empty
23+
* @param nullToEmptyMap Default: false. Whether to deserialize null values for a map property to an empty
2424
* map object.
25-
* @param nullIsSameAsDefault Default false. Whether to treat null values as absent when deserializing, thereby
25+
* @param nullIsSameAsDefault Default false. Whether to treat null values as absent when deserializing, thereby
2626
* using the default value provided in Kotlin.
27-
* @param singletonSupport Default: DISABLED. Mode for singleton handling.
27+
* @param singletonSupport Default: DISABLED. Mode for singleton handling.
2828
* See {@link com.fasterxml.jackson.module.kotlin.SingletonSupport label}
29-
* @param strictNullChecks Default: false. Whether to check deserialized collections. With this disabled,
29+
* @param strictNullChecks Default: false. Whether to check deserialized collections. With this disabled,
3030
* the default, collections which are typed to disallow null members
3131
* (e.g. List<String>) may contain null values after deserialization. Enabling it
3232
* protects against this but has significant performance impact.

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
4646
// (see https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html and
4747
// https://github.com/FasterXML/jackson-databind/issues/2527
4848
// for details)
49-
override fun findRenameByField(config: MapperConfig<*>,
50-
field: AnnotatedField,
51-
implName: PropertyName): PropertyName? {
49+
override fun findRenameByField(
50+
config: MapperConfig<*>,
51+
field: AnnotatedField,
52+
implName: PropertyName
53+
): PropertyName? {
5254
val origSimple = implName.simpleName
5355
if (field.declaringClass.isKotlinClass() && origSimple.startsWith("is")) {
5456
val mangledName: String? = BeanUtil.stdManglePropertyName(origSimple, 2)
@@ -93,10 +95,11 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
9395
}
9496

9597
override fun hasCreatorAnnotation(member: Annotated): Boolean =
96-
if (member is AnnotatedConstructor && member.isKotlinConstructorWithParameters())
98+
if (member is AnnotatedConstructor && member.isKotlinConstructorWithParameters()) {
9799
cache.checkConstructorIsCreatorAnnotated(member) { hasCreatorAnnotation(it) }
98-
else
100+
} else {
99101
false
102+
}
100103

101104
@Suppress("UNCHECKED_CAST")
102105
private fun findKotlinParameterName(param: AnnotatedParameter): String? {
@@ -105,9 +108,7 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
105108
if (member is Constructor<*>) {
106109
val ctor = (member as Constructor<Any>)
107110
val ctorParmCount = ctor.parameterTypes.size
108-
val ktorParmCount = try { ctor.kotlinFunction?.parameters?.size ?: 0 }
109-
catch (ex: KotlinReflectionInternalError) { 0 }
110-
catch (ex: UnsupportedOperationException) { 0 }
111+
val ktorParmCount = try { ctor.kotlinFunction?.parameters?.size ?: 0 } catch (ex: KotlinReflectionInternalError) { 0 } catch (ex: UnsupportedOperationException) { 0 }
111112
if (ktorParmCount > 0 && ktorParmCount == ctorParmCount) {
112113
ctor.kotlinFunction?.parameters?.get(param.index)?.name
113114
} else {
@@ -142,9 +143,9 @@ private fun AnnotatedConstructor.isKotlinConstructorWithParameters(): Boolean =
142143
parameterCount > 0 && declaringClass.isKotlinClass() && !declaringClass.isEnum
143144

144145
private fun KFunction<*>.isPossibleSingleString(propertyNames: Set<String>): Boolean = parameters.size == 1 &&
145-
parameters[0].name !in propertyNames &&
146-
parameters[0].type.javaType == String::class.java &&
147-
!parameters[0].hasAnnotation<JsonProperty>()
146+
parameters[0].name !in propertyNames &&
147+
parameters[0].type.javaType == String::class.java &&
148+
!parameters[0].hasAnnotation<JsonProperty>()
148149

149150
private fun Collection<KFunction<*>>.filterOutSingleStringCallables(propertyNames: Set<String>): Collection<KFunction<*>> =
150151
this.filter { !it.isPossibleSingleString(propertyNames) }

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import kotlin.reflect.KClass
1414
import kotlin.reflect.KFunction
1515
import kotlin.reflect.jvm.kotlinFunction
1616

17-
1817
internal class ReflectionCache(reflectionCacheSize: Int) {
1918
sealed class BooleanTriState(val value: Boolean?) {
2019
class True : BooleanTriState(true)
@@ -45,15 +44,14 @@ internal class ReflectionCache(reflectionCacheSize: Int) {
4544
private val javaMemberIsRequired = LRUMap<AnnotatedMember, BooleanTriState?>(reflectionCacheSize, reflectionCacheSize)
4645
private val kotlinGeneratedMethod = LRUMap<AnnotatedMethod, Boolean>(reflectionCacheSize, reflectionCacheSize)
4746

48-
4947
fun kotlinFromJava(key: Class<Any>): KClass<Any> = javaClassToKotlin.get(key)
50-
?: key.kotlin.let { javaClassToKotlin.putIfAbsent(key, it) ?: it }
48+
?: key.kotlin.let { javaClassToKotlin.putIfAbsent(key, it) ?: it }
5149

5250
fun kotlinFromJava(key: Constructor<Any>): KFunction<Any>? = javaConstructorToKotlin.get(key)
53-
?: key.kotlinFunction?.let { javaConstructorToKotlin.putIfAbsent(key, it) ?: it }
51+
?: key.kotlinFunction?.let { javaConstructorToKotlin.putIfAbsent(key, it) ?: it }
5452

5553
fun kotlinFromJava(key: Method): KFunction<*>? = javaMethodToKotlin.get(key)
56-
?: key.kotlinFunction?.let { javaMethodToKotlin.putIfAbsent(key, it) ?: it }
54+
?: key.kotlinFunction?.let { javaMethodToKotlin.putIfAbsent(key, it) ?: it }
5755

5856
/**
5957
* return null if...
@@ -85,11 +83,11 @@ internal class ReflectionCache(reflectionCacheSize: Int) {
8583
} // we cannot reflect this method so do the default Java-ish behavior
8684

8785
fun checkConstructorIsCreatorAnnotated(key: AnnotatedConstructor, calc: (AnnotatedConstructor) -> Boolean): Boolean = javaConstructorIsCreatorAnnotated.get(key)
88-
?: calc(key).let { javaConstructorIsCreatorAnnotated.putIfAbsent(key, it) ?: it }
86+
?: calc(key).let { javaConstructorIsCreatorAnnotated.putIfAbsent(key, it) ?: it }
8987

9088
fun javaMemberIsRequired(key: AnnotatedMember, calc: (AnnotatedMember) -> Boolean?): Boolean? = javaMemberIsRequired.get(key)?.value
91-
?: calc(key).let { javaMemberIsRequired.putIfAbsent(key, BooleanTriState.fromBoolean(it))?.value ?: it }
89+
?: calc(key).let { javaMemberIsRequired.putIfAbsent(key, BooleanTriState.fromBoolean(it))?.value ?: it }
9290

9391
fun isKotlinGeneratedMethod(key: AnnotatedMethod, calc: (AnnotatedMethod) -> Boolean): Boolean = kotlinGeneratedMethod.get(key)
94-
?: calc(key).let { kotlinGeneratedMethod.putIfAbsent(key, it) ?: it }
92+
?: calc(key).let { kotlinGeneratedMethod.putIfAbsent(key, it) ?: it }
9593
}

src/main/kotlin/com/fasterxml/jackson/module/kotlin/deser/deserializers/UnsignedIntegerCheckers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal sealed class UnsignedIntegerChecker<T : Comparable<T>, U : Comparable<U
1616
?.convert()
1717
?: throw InputCoercionException(
1818
p,
19-
"Numeric value (${value}) out of range of ${clazz.simpleName} (${min} - ${max}).",
19+
"Numeric value ($value) out of range of ${clazz.simpleName} ($min - $max).",
2020
JsonToken.VALUE_NUMBER_INT,
2121
clazz
2222
)

src/main/kotlin/com/fasterxml/jackson/module/kotlin/deser/value_instantiator/KotlinValueInstantiator.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import com.fasterxml.jackson.databind.deser.ValueInstantiators
99
import com.fasterxml.jackson.databind.deser.impl.NullsAsEmptyProvider
1010
import com.fasterxml.jackson.databind.deser.impl.PropertyValueBuffer
1111
import com.fasterxml.jackson.databind.deser.std.StdValueInstantiator
12-
import com.fasterxml.jackson.module.kotlin.deser.value_instantiator.creator.ConstructorValueCreator
13-
import com.fasterxml.jackson.module.kotlin.deser.value_instantiator.creator.MethodValueCreator
1412
import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
1513
import com.fasterxml.jackson.module.kotlin.ReflectionCache
14+
import com.fasterxml.jackson.module.kotlin.deser.value_instantiator.creator.ConstructorValueCreator
15+
import com.fasterxml.jackson.module.kotlin.deser.value_instantiator.creator.MethodValueCreator
1616
import com.fasterxml.jackson.module.kotlin.deser.value_instantiator.creator.ValueCreator
1717
import com.fasterxml.jackson.module.kotlin.isKotlinClass
1818
import com.fasterxml.jackson.module.kotlin.wrapWithPath
@@ -71,7 +71,7 @@ internal class KotlinValueInstantiator(
7171
}
7272
tempParamVal
7373
} else {
74-
if(paramDef.type.isMarkedNullable) {
74+
if (paramDef.type.isMarkedNullable) {
7575
// do not try to create any object if it is nullable and the value is missing
7676
null
7777
} else {
@@ -87,7 +87,8 @@ internal class KotlinValueInstantiator(
8787
val isGenericTypeVar = paramDef.type.javaType is TypeVariable<*>
8888
val isMissingAndRequired = paramVal == null && isMissing && jsonProp.isRequired
8989
if (isMissingAndRequired ||
90-
(!isGenericTypeVar && paramVal == null && !paramDef.type.isMarkedNullable)) {
90+
(!isGenericTypeVar && paramVal == null && !paramDef.type.isMarkedNullable)
91+
) {
9192
throw MissingKotlinParameterException(
9293
parameter = paramDef,
9394
processor = ctxt.parser,
@@ -141,7 +142,6 @@ internal class KotlinValueInstantiator(
141142
}
142143
valueCreator.callBy(callableParametersByName)
143144
}
144-
145145
}
146146

147147
private fun KParameter.isPrimitive(): Boolean {

src/main/kotlin/com/fasterxml/jackson/module/kotlin/deser/value_instantiator/creator/ValueCreator.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ internal sealed class ValueCreator<T> {
2828

2929
/**
3030
* Checking process to see if access from context is possible.
31-
* @throws IllegalAccessException
31+
* @throws IllegalAccessException
3232
*/
3333
fun checkAccessibility(ctxt: DeserializationContext) {
3434
if ((!accessible && ctxt.config.isEnabled(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS)) ||
35-
(accessible && ctxt.config.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS))) {
35+
(accessible && ctxt.config.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS))
36+
) {
3637
return
3738
}
3839

0 commit comments

Comments
 (0)