6

I am trying to save SearchAvailableRidesRequestOffline to android Shared Preferences. I need to deserialise the object to use it later on. While I try to deserialise it from json, I am getting this exception.

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; } } 
10
  • Just code and no time to write any words? what you are doing and when do you get this exception? Commented May 10, 2018 at 11:42
  • Sorry, making corrections now.. Seems crazy :) Commented May 10, 2018 at 18:12
  • Try adding a private setRequest(ARequest) method as well and see if that helps Commented May 10, 2018 at 20:53
  • Nope does not work, tried that. Commented May 11, 2018 at 4:36
  • What is the source object that you try to serialize? Commented May 11, 2018 at 6:00

1 Answer 1

2

Remember:

  • if the .json content starts with { is considered as a Json Object.

  • if the .json content starts with [ is considered as a Json Array.

You have this error

com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (START_OBJECT), expected START_ARRAY:

because you are expecting an Json Array but your response is a Json Object:

"{ "request" : { ... ... 

Check your response.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.