D/OkHttp: Callback failure for call to http://10.0.2.2:5000/...
D/OkHttp: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token
D/OkHttp: at [Source: (String)"{"recurrenceId":1,"meetingId":4,"weekDay":21}"; line: 1, column: 1]
D/OkHttp: at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1343)
D/OkHttp: at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1139)
D/OkHttp: at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1093)
D/OkHttp: at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.handleNonArray(CollectionDeserializer.java:332)
D/OkHttp: at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:265)
D/OkHttp: at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:245)
D/OkHttp: at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
D/OkHttp: at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3023)
D/OkHttp: at fr.intech.neith.api.RecurrenceApi.toDo(RecurrenceApi.kt:34)
at fr.intech.neith.helpers.ApiHelper$GET$1.onResponse(ApiHelper.kt:35)
D/OkHttp: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
D/OkHttp: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
D/OkHttp: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
package fr.intech.neith.models
data class Recurrence(val recurrenceId: Int = 0,
val meetingId: Int = 0,
val weekDay: Array<Int> = arrayOf())
package fr.intech.neith.api
import...
class RecurrenceApi(context: Context): IOnApiResponse {
var itodo: IToDoRecurrenceList? = null
override fun toDo(body: String) {
val mapper = ObjectMapper()
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
//val reader: ObjectReader = mapper.reader().forType(Meeting.class);
val reader = mapper.readValue<MutableList<Recurrence>>(body)
itodo!!.toExecuteR(reader)
}
var client = OkHttpClient()
var api = ApiHelper(client, context)
var url: String = "http://10.0.2.2:5000" + "/api/recurrence" // 192.168.43.135 4G - 10.0.2.2 ÉMULATEUR
fun getRecurrenceList(meetingId: Int, cb: IToDoRecurrenceList) {
val url2: String = url + "/${meetingId}";
itodo = cb
api.GET(url2, this)
}
}
package fr.intech.neith.models
import java.io.Serializable
import java.util.*
data class Meeting(val hostFirstName: String = "",
val hostLastName: String = "",
val estimatedTime: String = "",
val startDate: Date = Date(),
val meetingId: Int = 0,
val name: String = "",
val hasEnded: Boolean = false,
val hostId: Int = 0,
val recurrence: Array<Int> = arrayOf(),
val index: Int = 0,
val isRecurrent: Boolean = false): Serializable
package fr.intech.neith.api
import android.content.Context
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import fr.intech.neith.IOnApiResponse
import fr.intech.neith.IToDoList
import fr.intech.neith.helpers.*
import fr.intech.neith.models.Meeting
import okhttp3.OkHttpClient
class MeetingApi(context: Context): IOnApiResponse {
var itodo: IToDoList<Meeting>? = null
override fun toDo(body: String) {
val mapper = ObjectMapper()
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
val reader = mapper.readValue<MutableList<Meeting>>(body)
itodo!!.toExecute(reader)
}
var client = OkHttpClient()
var api = ApiHelper(client, context)
var url: String = "http://10.0.2.2:5000" + "/api/meeting" // 192.168.43.135 4G - 10.0.2.2 ÉMULATEUR
fun getMeetingList(userId: Int, cb: IToDoList<Meeting>) {
val url2: String = url + "/${userId}/names"
itodo = cb
api.GET(url2, this)
}
}
谢谢你的回答。
编辑:这解决了问题:mapper.configure(deserializationfeature.accept_single_value_as_array,true)
从https://craftsmen.nl/kotlin-create-rest-services-using-jersey-and-jackson/:
为了反序列化Kotlin数据类,我们必须在ObjectMapper实例上注册Jackson的KotlinModule。
https://github.com/fasterxml/jackson-module-kotlin
我从Fitbit API得到一个json字符串。我想在列表对象中保存dateTime和value字段。我用的是jackson模块Kotlin。我为此创建了ActivitiesSteps数据类。 下面是我使用Jackson的代码: 并引发以下异常:
无法将Json反序列化为列表集合。我使用的是Lombok,它保存字段变量: 我该怎么修好它?
我想从angular 8前端向spring boot API发送一个JSON对象。我是这些框架的新手,我有点迷茫。 错误: “无法将的实例从START_OBJECT标记反序列化到[源:(String)”{“coordines”:[{“lat”:76.00542202728906,“lng”:-71.76493508359451},{“lat”:62.96921913888247,“lng”:-11
当然,所有依赖项(子类追加在同一个字符串中)。 从外部API获取数据的代码是; 当我运行代码并试图获取adress“API/3”时,出现以下错误:
我的映射器是: 如果我删除列表freq并改为字符串freq,它可以工作,但我的JSON可以包含一个或多个freq,所以我需要创建一个列表。我得到的异常如下:
问题内容: 我正在尝试发布自定义对象。我在请求正文中的JSON是这样的: 处理请求的服务器端代码: 实体: 但是抛出一个异常: 问题答案: 问题是JSON-默认情况下不能反序列化为,因为它实际上不是JSON数组-看起来像这样: 由于你没有控制反序列化的确切过程(RestEasy确实如此)- 第一个选择是简单地将JSON作为a注入String,然后控制反序列化过程: 你不必自己进行操作便会失去一些便