com.fasterxml.jackson.databind.exc.MismatchedInputException:意外的令牌(START_OBJECT),预期的START_ARRAY:
Posted
技术标签:
【中文标题】com.fasterxml.jackson.databind.exc.MismatchedInputException:意外的令牌(START_OBJECT),预期的START_ARRAY:【英文标题】:com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (START_OBJECT), expected START_ARRAY: 【发布时间】:2018-09-24 02:53:58 【问题描述】:我正在尝试将 SearchAvailableRidesRequestOffline
保存到 android Shared Preferences
。我需要deserialise
该对象以便稍后使用它。当我尝试从json
发送deserialise
时,我遇到了这个异常。
IOException
com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (START_OBJECT), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class com.mnox.webservices.core.ARequest
at [Source: (String)"
"request" :
.....
"filterType"[truncated 882 chars]; line: 2, column: 15] (through reference chain: com.mnox.paymentgateway.commons.support.offline.SearchAvailableRidesRequestOffline["request"])
JSON
"request" :
//
// SearchAvailableRidesRequest
// Parameters
,
"concreateRequestClass" : "com.mnox.webservices.requests.v2.SearchAvailableRidesRequest",
"currentActivity" : null,
"maxLimitAllowed" : 1000,
"priority" : 0,
"requestType" : "mNoxSearch"
Java
public class SearchAvailableRidesRequestOffline extends AOfflineRequest implements IModelRequestedController
public SearchAvailableRidesRequestOffline()
public SearchAvailableRidesRequestOffline(SearchAvailableRidesRequest searchRequest)
super(searchRequest);
@Override
public int getMaxLimitAllowed()
return 1000;
@Override
public int getPriority()
return 0;
@Override
public void onModelRequestCompleted(IModelRequestedController context, int modelIdentifier,
Object modelData)
@Override
public RequestType getRequestType()
return RequestType.mNoxSearch;
@Override
public Activity getCurrentActivity()
return null;
@Override
public Class getConcreateRequestClass() return SearchAvailableRidesRequest.class; ;
public abstract class AOfflineRequest
public static enum RequestType mNoxSearch, mNoxDriverCurrentLocation ;
private ARequest request;
public AOfflineRequest(ARequest request)
this.request = request;
public void updatePreExecuteProgressBar()
public void updatePostExecuteProgressBar()
public abstract RequestType getRequestType() ;
public abstract Class getConcreateRequestClass() ;
public abstract int getMaxLimitAllowed();
public abstract int getPriority();
//
// For gson
//
public AOfflineRequest()
public ARequest getRequest()
return request;
【问题讨论】:
只写代码没时间写字?你在做什么,什么时候得到这个异常? 抱歉,现在更正.. 看起来很疯狂 :) 尝试添加一个private setRequest(ARequest)
方法,看看是否有帮助
不行,试过了。
您尝试序列化的源对象是什么?
【参考方案1】:
记住:
如果 .json 内容以 开头,则视为 Json 对象。
如果 .json 内容以 [ 开头,则视为 Json 数组。
你有这个错误
com.fasterxml.jackson.databind.exc.MismatchedInputException: 意外令牌 (START_OBJECT),预期 START_ARRAY:
因为您期待一个 Json 数组,但您的响应是一个 Json 对象:
"
"request" :
...
...
检查您的回复。
【讨论】:
以上是关于com.fasterxml.jackson.databind.exc.MismatchedInputException:意外的令牌(START_OBJECT),预期的START_ARRAY:的主要内容,如果未能解决你的问题,请参考以下文章