Я получаю InvalidDefinitionException
при разборе JSON в моем собственном классе.Исключительная ситуация в потоке "main"] не имеет аннотации имени свойства;должен иметь имя, когда конструктор с несколькими параметрами аннотирован как Creator в [Source: (String) "…"
Вот строка, которая вызывает проблемы:
val wrapper: BookWrapper = mapper.reader().forType(BookWrapper::class.java).readValue("""
{
"book": {
"publisher": "Pearson",
"image": "https:\/\/images.isbndb.com\/covers\/34\/13\/9780134093413.jpg",
"title_long": "Campbell Biology (11th Edition)",
"edition": "11",
"date_published": "2016-10-29",
"authors": [
"Lisa A. Urry",
"Michael L. Cain",
"Steven A. Wasserman",
"Peter V. Minorsky",
"Jane B. Reece"
],
"title": "Campbell Biology (11th Edition)",
"isbn13": "9780134093413",
"binding": "Hardcover",
"publish_date": "2016-10-29",
"isbn": "0134093410"
}
}""")
А вот мой bookwrapperкласс:
data class BookWrapper(@JsonProperty("book") val book: Book)
@JsonInclude(JsonInclude.Include.NON_NULL)
data class Book(
val title: String,
@JsonProperty("title_long")
val titleLong: String? = null,
val isbn: String? = null,
val isbn13: String? = null,
val dewey_decimal: String? = null,
val format: String? = null,
val publisher: String? = null,
val publish: String? = null,
val language: String? = null,
@JsonProperty("date_published")
val datePublished: String? = null,
@JsonProperty("publish_date")
val publishDate: String? = null,
val edition: String? = null,
val pages: String? = null,
val binding: String? = null,
val dimensions: String? = null,
val overview: String? = null,
val excerpt: String? = null,
val synopsys: String? = null,
val image: String? = null,
val authors: List<String>,
val subjects: List<String>? = null,
var id: Long? = null,
var amount: Int = 1
)
РЕДАКТИРОВАТЬ :
Я забыл зарегистрировать KotlinModule.Не забудьте сделать это.