I have the following situation:
A custom RestDataSource where i want to override transformResponse method to create custom Records.
Here is the code:
If i use DSDataFormat.CUSTON, the code above works fine, but when i use this data format response.getStatus() always return zero, and is hard to handle errors.
So i tried to use DSDataFormat.JSON, for simple JSON this works, but when i have a JSON like that:
the data param in transformResponse method looks like this:
I'm doing something wrong? What i need to do to get this json in the right format?
A custom RestDataSource where i want to override transformResponse method to create custom Records.
Here is the code:
Code:
@Override protected final void transformResponse(DSResponse response, DSRequest request,Object data) { if (response.getStatus() == DSResponse.STATUS_SUCCESS && request.getOperationType() == DSOperationType.FETCH) internalFetch(response, request, data); else super.transformResponse(response, request, data); } protected void internalFetch(DSResponse response, DSRequest request, Object data) { //response.getStatus() JSONObject jsonObjt = getResponse(data); JSONObject responseJSON = jsonObjt.get("response").isObject(); JSONArray dados = responseJSON.get("data").isArray(); Record[] dataArray = new Record[dados.size()]; for (int i = 0; i < dados.size(); i++) { dataArray[i] = newRecord(dados.get(i).isObject()); } }
If i use DSDataFormat.CUSTON, the code above works fine, but when i use this data format response.getStatus() always return zero, and is hard to handle errors.
So i tried to use DSDataFormat.JSON, for simple JSON this works, but when i have a JSON like that:
Code:
data[{ code:1, description:'TEST', family: { code:10 } }]
Code:
data[{ code:1, description:'TEST', family: {[object Object]} }]
I'm doing something wrong? What i need to do to get this json in the right format?