Skip to content

Commit 4bd73bb

Browse files
committed
Revert "Extract missing parameter check"
This reverts commit 074d87d.
1 parent 35bd79d commit 4bd73bb

File tree

1 file changed

+74
-41
lines changed

1 file changed

+74
-41
lines changed

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

+74-41
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,43 @@ internal class KotlinValueInstantiator(
6666
paramVal = NullsAsEmptyProvider(jsonProp.valueDeserializer).getNullValue(ctxt)
6767
}
6868

69-
throwIfMissingParameter(paramDef, paramVal, isMissing, jsonProp, ctxt)
69+
val isGenericTypeVar = paramDef.type.javaType is TypeVariable<*>
70+
val isMissingAndRequired = paramVal == null && isMissing && jsonProp.isRequired
71+
if (isMissingAndRequired ||
72+
(!isGenericTypeVar && paramVal == null && !paramDef.type.isMarkedNullable)) {
73+
throw MissingKotlinParameterException(
74+
parameter = paramDef,
75+
processor = ctxt.parser,
76+
msg = "Instantiation of ${this.valueTypeDesc} value failed for JSON property ${jsonProp.name} due to missing (therefore NULL) value for creator parameter ${paramDef.name} which is a non-nullable type"
77+
).wrapWithPath(this.valueClass, jsonProp.name)
78+
}
79+
80+
if (strictNullChecks && paramVal != null) {
81+
var paramType: String? = null
82+
var itemType: KType? = null
83+
if (jsonProp.type.isCollectionLikeType && paramDef.type.arguments.getOrNull(0)?.type?.isMarkedNullable == false && (paramVal as Collection<*>).any { it == null }) {
84+
paramType = "collection"
85+
itemType = paramDef.type.arguments[0].type
86+
}
87+
88+
if (jsonProp.type.isMapLikeType && paramDef.type.arguments.getOrNull(1)?.type?.isMarkedNullable == false && (paramVal as Map<*, *>).any { it.value == null }) {
89+
paramType = "map"
90+
itemType = paramDef.type.arguments[1].type
91+
}
92+
93+
if (jsonProp.type.isArrayType && paramDef.type.arguments.getOrNull(0)?.type?.isMarkedNullable == false && (paramVal as Array<*>).any { it == null }) {
94+
paramType = "array"
95+
itemType = paramDef.type.arguments[0].type
96+
}
97+
98+
if (paramType != null && itemType != null) {
99+
throw MissingKotlinParameterException(
100+
parameter = paramDef,
101+
processor = ctxt.parser,
102+
msg = "Instantiation of $itemType $paramType failed for JSON property ${jsonProp.name} due to null value in a $paramType that does not allow null values"
103+
).wrapWithPath(this.valueClass, jsonProp.name)
104+
}
105+
}
70106

71107
bucket[idx] = paramVal
72108
}
@@ -159,7 +195,43 @@ internal class KotlinValueInstantiator(
159195
paramVal = NullsAsEmptyProvider(jsonProp.valueDeserializer).getNullValue(ctxt)
160196
}
161197

162-
throwIfMissingParameter(paramDef, paramVal, isMissing, jsonProp, ctxt)
198+
val isGenericTypeVar = paramDef.type.javaType is TypeVariable<*>
199+
val isMissingAndRequired = paramVal == null && isMissing && jsonProp.isRequired
200+
if (isMissingAndRequired ||
201+
(!isGenericTypeVar && paramVal == null && !paramDef.type.isMarkedNullable)) {
202+
throw MissingKotlinParameterException(
203+
parameter = paramDef,
204+
processor = ctxt.parser,
205+
msg = "Instantiation of ${this.valueTypeDesc} value failed for JSON property ${jsonProp.name} due to missing (therefore NULL) value for creator parameter ${paramDef.name} which is a non-nullable type"
206+
).wrapWithPath(this.valueClass, jsonProp.name)
207+
}
208+
209+
if (strictNullChecks && paramVal != null) {
210+
var paramType: String? = null
211+
var itemType: KType? = null
212+
if (jsonProp.type.isCollectionLikeType && paramDef.type.arguments.getOrNull(0)?.type?.isMarkedNullable == false && (paramVal as Collection<*>).any { it == null }) {
213+
paramType = "collection"
214+
itemType = paramDef.type.arguments[0].type
215+
}
216+
217+
if (jsonProp.type.isMapLikeType && paramDef.type.arguments.getOrNull(1)?.type?.isMarkedNullable == false && (paramVal as Map<*, *>).any { it.value == null }) {
218+
paramType = "map"
219+
itemType = paramDef.type.arguments[1].type
220+
}
221+
222+
if (jsonProp.type.isArrayType && paramDef.type.arguments.getOrNull(0)?.type?.isMarkedNullable == false && (paramVal as Array<*>).any { it == null }) {
223+
paramType = "array"
224+
itemType = paramDef.type.arguments[0].type
225+
}
226+
227+
if (paramType != null && itemType != null) {
228+
throw MissingKotlinParameterException(
229+
parameter = paramDef,
230+
processor = ctxt.parser,
231+
msg = "Instantiation of $itemType $paramType failed for JSON property ${jsonProp.name} due to null value in a $paramType that does not allow null values"
232+
).wrapWithPath(this.valueClass, jsonProp.name)
233+
}
234+
}
163235

164236
jsonParamValueList[numCallableParameters] = paramVal
165237
callableParameters[numCallableParameters] = paramDef
@@ -186,45 +258,6 @@ internal class KotlinValueInstantiator(
186258
}
187259
}
188260

189-
private fun throwIfMissingParameter(paramDef: KParameter, paramVal: Any?, isMissing: Boolean, jsonProp: SettableBeanProperty, ctxt: DeserializationContext) {
190-
val isGenericTypeVar = paramDef.type.javaType is TypeVariable<*>
191-
val isMissingAndRequired = paramVal == null && isMissing && jsonProp.isRequired
192-
if (isMissingAndRequired || (!isGenericTypeVar && paramVal == null && !paramDef.type.isMarkedNullable)) {
193-
throw MissingKotlinParameterException(
194-
parameter = paramDef,
195-
processor = ctxt.parser,
196-
msg = "Instantiation of ${this.valueTypeDesc} value failed for JSON property ${jsonProp.name} due to missing (therefore NULL) value for creator parameter ${paramDef.name} which is a non-nullable type"
197-
).wrapWithPath(this.valueClass, jsonProp.name)
198-
}
199-
200-
if (strictNullChecks && paramVal != null) {
201-
var paramType: String? = null
202-
var itemType: KType? = null
203-
if (jsonProp.type.isCollectionLikeType && paramDef.type.arguments.getOrNull(0)?.type?.isMarkedNullable == false && (paramVal as Collection<*>).any { it == null }) {
204-
paramType = "collection"
205-
itemType = paramDef.type.arguments[0].type
206-
}
207-
208-
if (jsonProp.type.isMapLikeType && paramDef.type.arguments.getOrNull(1)?.type?.isMarkedNullable == false && (paramVal as Map<*, *>).any { it.value == null }) {
209-
paramType = "map"
210-
itemType = paramDef.type.arguments[1].type
211-
}
212-
213-
if (jsonProp.type.isArrayType && paramDef.type.arguments.getOrNull(0)?.type?.isMarkedNullable == false && (paramVal as Array<*>).any { it == null }) {
214-
paramType = "array"
215-
itemType = paramDef.type.arguments[0].type
216-
}
217-
218-
if (paramType != null && itemType != null) {
219-
throw MissingKotlinParameterException(
220-
parameter = paramDef,
221-
processor = ctxt.parser,
222-
msg = "Instantiation of $itemType $paramType failed for JSON property ${jsonProp.name} due to null value in a $paramType that does not allow null values"
223-
).wrapWithPath(this.valueClass, jsonProp.name)
224-
}
225-
}
226-
}
227-
228261
override fun createFromObjectWith(
229262
ctxt: DeserializationContext,
230263
props: Array<out SettableBeanProperty>,

0 commit comments

Comments
 (0)