sumesh sumesh - 1 year ago 142
Java Question

Retrofit - Android - Expected BEGIN_ARRAY but was BEGIN_OBJECT

I am trying to parse following JSON data using Retrofit

"message": false,
"suggestions": false,
"vehicle": {
"parked": true,
"uin": "15",
"vin": "WBAEG1312MCB42267",
"make": "Bmw",
"model": "E8SERIES",
"color": "Blue",
"year": "1991",
"package": "Premium",
"options": "",
"interior": "Color: Cream, Type:Leather",
"exterior": "",
"activity": "Parked",
"username": "Dhruba Sarma",
"timestamp": "04-Sep, 00:35",
"latlng": {
"lat": 12.899270164792,
"lng": 77.646080134509

I have created my model classes as follows -

`public class VehicleModel {

private Boolean message;
private Boolean suggestions;
private Vehicle vehicle;

public Boolean getMessage() {
return message;

public Boolean getSuggestions() {
return suggestions;

public Vehicle getVehicle() {
return vehicle;
`public class Vehicle {

private Boolean parked;
private String uin;
private String vin;
private String make;
private String model;
private String color;
private String year;
private String _package;
private String options;
private String interior;
private String exterior;
private String activity;
private String username;
private String timestamp;
private LatLng latlng;

public Boolean getParked() {
return parked;

public String getUin() {
return uin;

public String getVin() {
return vin;

public String getMake() {
return make;

public String getModel() {
return model;

public String getColor() {
return color;

public String getYear() {
return year;

public String getPackage() {
return _package;

public String getOptions() {
return options;

public String getInterior() {
return interior;

public String getExterior() {
return exterior;

public String getActivity() {
return activity;

public String getUsername() {
return username;

public String getTimestamp() {
return timestamp;

public LatLng getLatlng() {
return latlng;


And finally
`public class LatLng {

private Double lat;
private Double lng;

public Double getLat() {
return lat;

public Double getLng() {
return lng;

I even tried using jsonschema2pojo for reference. But i still get the below error java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT

Please suggest what am i doing wrong ?

EDIT- Here is how i am parsing JSON

Retrofit retrofit = new Retrofit.Builder().baseUrl(baseUrl)

VehicleRequestInterface request = retrofit.create(VehicleRequestInterface.class);
Call<VehicleJSONResponse> call = request.getVehicleJSON(url);
call.enqueue(new Callback<VehicleJSONResponse>() {
public void onResponse(Call<VehicleJSONResponse> call, Response<VehicleJSONResponse> response) {

VehicleJSONResponse jsonResponse = response.body();
vehicleData = new ArrayList<>(Arrays.asList(jsonResponse.getVehicle()));

Answer Source

Declare your vehicleData variable like this .

ArrayList<VehicleModel> vehicleData = new ArrayList<VehicleModel>();

And then in onResponse rather than

vehicleData = new ArrayList<>(Arrays.asList(jsonResponse.getVehicle()));

add like this way


The problem is you have no arrays in your json

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download