Fail on sealed classes in KotlinJsonAdapterFactory and code gen (#914)

Resolves #906
This commit is contained in:
Zac Sweers
2019-09-12 20:38:46 -04:00
committed by GitHub
parent a67b4d6a72
commit dd0e3807d3
4 changed files with 41 additions and 0 deletions

View File

@@ -202,6 +202,9 @@ class KotlinJsonAdapterFactory : JsonAdapter.Factory {
require(rawTypeKotlin.objectInstance == null) {
"Cannot serialize object declaration ${rawType.name}"
}
require(!rawTypeKotlin.isSealed) {
"Cannot reflectively serialize sealed class ${rawType.name}. Please register an adapter."
}
val constructor = rawTypeKotlin.primaryConstructor ?: return null
val parametersByName = constructor.parameters.associateBy { it.name }