This error is back !
I'm a beginner with Retrofit, I've saw this post: Retrofit: Expected BEGIN_OBJECT but was BEGIN_ARRAY
But I still can't make it work even if I try to adapt it to my model. So my error is:
Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 55 path $[0].genericDevice
What I get:
[
{
"deviceUuid": "btB4:99:4C:59:F8:1F",
"genericDevice": {
"manufacturerName": "BeeWi",
"productName": "BeeWi BBL207",
"smartFunctions": [
"switch",
"rgbled",
"whiteled"
]
}
},
{
"deviceUuid": "btD0:39:72:B8:93:F2",
"genericDevice": {
"manufacturerName": "AwoX",
"productName": "SML-c9",
"smartFunctions": [
"switch",
"whiteled",
"rgbled"
]
}
},
{
"deviceUuid": "bt20:C3:8F:E4:B2:2A",
"genericDevice": {
"manufacturerName": "Iwedia",
"productName": "RTRKSP",
"smartFunctions": [
"switch",
"smartmeter"
]
}
},
{
"deviceUuid": "btA0:14:3D:0C:D3:74",
"genericDevice": {
"manufacturerName": "Parrot",
"productName": "Flower power",
"smartFunctions": [
"switch",
"battery",
"plantmanager"
]
}
},
{
"deviceUuid": "bt78:A5:04:5A:0B:36",
"genericDevice": {
"manufacturerName": "BeeWi",
"productName": "BeeWi SmartClim",
"smartFunctions": [
"temperaturehumidity"
]
}
},
{
"deviceUuid": "bt54:4A:16:59:E4:86",
"genericDevice": {
"manufacturerName": "AwoX",
"productName": "AL-Bc7",
"smartFunctions": [
"switch",
"rgbled",
"whiteled",
"oildiffuser"
]
}
}
]
The parsing class' attributes:
private String deviceUuid;
private IoTGenericDevice ioTGncDvc;
The IoTGenericDevice subclass' attributes:
public String manufacturerName;
public String productName;
public ArrayList<String> smartFunctions = new ArrayList<String>();
The Retrofit call:
@GET("/iot/scanning")
public void getIoTs(@Header(Auth.ID_SESSION_HEADER) String idSession, Callback<IoT[]> cbk);
The Manager:
public void getIoTs(final CallbackIoTs cbkIoTs)
{
AdapterUtils.createBboxService(bbox, IBboxIoTService.class).getIoTs
(bbox.getSessionId(), new Callback<List<IoT>>() //REST call
{
@Override
public void success(List<IoT> iots, Response rsp)
{
int statCode = rsp.getStatus();
if (statCode == 200) {
List<IoT> iotLst = Arrays.asList(iots);
Log.e(LOG_TAG, iotLst.get(0).getIoTGncDvc().getMnf());
cbkIoTs.onResult(statCode, iotLst);
} else {
Log.e(LOG_TAG, "Unexpected response while getting IoTs. HTTP code: "
+ String.valueOf(statCode)
+ " - 200 expected");
cbkIoTs.onResult(statCode, null);
}
}
@Override
public void failure(RetrofitError rtfErr)
{
int statCode = 500;
if (rtfErr.getResponse() != null)
statCode = rtfErr.getResponse().getStatus();
Log.e(LOG_TAG, "Error while getting IoTs. HTTP code: "
+ String.valueOf(statCode)
+ " - Server response: "
+ rtfErr.getMessage());
cbkIoTs.onResult(statCode, null);
}
});
}