mirror of
https://github.com/fankes/moshi.git
synced 2025-10-19 16:09:21 +08:00
@@ -213,18 +213,14 @@ class KotlinJsonAdapterFactory : JsonAdapter.Factory {
|
|||||||
val parameter = parametersByName[property.name]
|
val parameter = parametersByName[property.name]
|
||||||
|
|
||||||
if (Modifier.isTransient(property.javaField?.modifiers ?: 0)) {
|
if (Modifier.isTransient(property.javaField?.modifiers ?: 0)) {
|
||||||
@Suppress("ReplaceGuardClauseWithFunctionCall") // More readable this way
|
require(parameter == null || parameter.isOptional) {
|
||||||
if (parameter != null && !parameter.isOptional) {
|
"No default value for transient constructor $parameter"
|
||||||
throw IllegalArgumentException(
|
|
||||||
"No default value for transient constructor $parameter")
|
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("ReplaceGuardClauseWithFunctionCall") // More readable this way
|
require(parameter == null || parameter.type == property.returnType) {
|
||||||
if (parameter != null && parameter.type != property.returnType) {
|
"'${property.name}' has a constructor parameter of type ${parameter!!.type} but a property of type ${property.returnType}."
|
||||||
throw IllegalArgumentException("'${property.name}' has a constructor parameter of type " +
|
|
||||||
"${parameter.type} but a property of type ${property.returnType}.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property !is KMutableProperty1 && parameter == null) continue
|
if (property !is KMutableProperty1 && parameter == null) continue
|
||||||
@@ -254,7 +250,9 @@ class KotlinJsonAdapterFactory : JsonAdapter.Factory {
|
|||||||
|
|
||||||
for (parameter in constructor.parameters) {
|
for (parameter in constructor.parameters) {
|
||||||
val binding = bindingsByName.remove(parameter.name)
|
val binding = bindingsByName.remove(parameter.name)
|
||||||
require(!(binding == null && !parameter.isOptional)) { "No property for required constructor $parameter" }
|
require(binding != null || parameter.isOptional) {
|
||||||
|
"No property for required constructor $parameter"
|
||||||
|
}
|
||||||
bindings += binding
|
bindings += binding
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user