Correct error for duplicate JSON key for Kotlin. (#789)

Before, the KotlinJsonAdapter threw "java.lang.IndexOutOfBoundsException: Index: 0, Size: 0" on a duplicate key when the key matched a property that was not a constructor parameter.
This commit is contained in:
Eric Cochran
2019-02-15 11:18:50 -08:00
committed by GitHub
parent 126c8ea961
commit 13a40edf5b
3 changed files with 43 additions and 10 deletions

View File

@@ -17,7 +17,6 @@ package com.squareup.moshi.kotlin.reflect
import com.squareup.moshi.Json
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonClass
import com.squareup.moshi.JsonDataException
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
@@ -77,7 +76,7 @@ internal class KotlinJsonAdapter<T>(
if (values[index] !== ABSENT_VALUE) {
throw JsonDataException(
"Multiple values for '${constructor.parameters[index].name}' at ${reader.path}")
"Multiple values for '${binding.property.name}' at ${reader.path}")
}
values[index] = binding.adapter.fromJson(reader)