Start a new topic

Save returns onFailure but entity does get saved in the collection....

I have a strange case. I am doing a save of an entity in a collection and even though the entity gets saved correctly to Kinvey backend, the onFailure gets called instead of onSuccess with the following error message:


E/KINVEY_SUMMARY(11858): com.kinvey.java.KinveyException: 

E/KINVEY_SUMMARY(11858): REASON: Unable to parse the JSON in the response

E/KINVEY_SUMMARY(11858): FIX: examine BL or DLC to ensure data format is correct. If the exception is caused by `key <somkey>`, then <somekey> might be a different type than is expected (int instead of of string)

E/KINVEY_SUMMARY(11858): EXPLANATION: java.lang.IllegalArgumentException: 

E/KINVEY_SUMMARY(11858): 

E/KINVEY_SUMMARY(11858): at com.kinvey.java.core.AbstractKinveyClientRequest.execute(AbstractKinveyClientRequest.java:484)

E/KINVEY_SUMMARY(11858): at com.kinvey.java.offline.AbstractKinveyOfflineClientRequest.offlineFromService(AbstractKinveyOfflineClientRequest.java:130)

E/KINVEY_SUMMARY(11858): at com.kinvey.java.offline.OfflinePolicy$1.execute(OfflinePolicy.java:42)

E/KINVEY_SUMMARY(11858): at com.kinvey.java.offline.AbstractKinveyOfflineClientRequest.execute(AbstractKinveyOfflineClientRequest.java:156)

E/KINVEY_SUMMARY(11858): at com.kinvey.android.AsyncAppData$SaveRequest.executeAsync(AsyncAppData.java:625)

E/KINVEY_SUMMARY(11858): at com.kinvey.android.AsyncClientRequest.doInBackground(AsyncClientRequest.java:71)

E/KINVEY_SUMMARY(11858): at android.os.AsyncTask$2.call(AsyncTask.java:287)

E/KINVEY_SUMMARY(11858): at java.util.concurrent.FutureTask.run(FutureTask.java:234)

E/KINVEY_SUMMARY(11858): at com.kinvey.android.AsyncClientRequest$KinveySerialExecutor$1.run(AsyncClientRequest.java:145)

E/KINVEY_SUMMARY(11858): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)

E/KINVEY_SUMMARY(11858): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)

E/KINVEY_SUMMARY(11858): at java.lang.Thread.run(Thread.java:856)



I am unable to figure out how to go about fixing this issue or whats the issue in the first place.


1 person has this question

Hello Pankaj,  


Can you enable debugging as outlined in: http://devcenter.kinvey.com/android/guides/troubleshooting


If you are running an older version of the library there may be a different process to enable debug logging.


Thanks,

@Damien


Here is the detailed log. I am not sure why the JSON parse in response is failing as the response JSOn seems to be valid and I am using GenericJson in the callback:


07-28 16:04:27.587 D/HttpTransport( 8764): -------------- REQUEST --------------

07-28 16:04:27.587 D/HttpTransport( 8764): POST https://baas.kinvey.com/appdata/kid_-yj4pCgcq/00CCUAlerts/_group

07-28 16:04:27.587 D/HttpTransport( 8764): Accept-Encoding: gzip

07-28 16:04:27.587 D/HttpTransport( 8764): Authorization: <Not Logged>

07-28 16:04:27.587 D/HttpTransport( 8764): Content-Type: application/json; charset=UTF-8

07-28 16:04:27.587 D/HttpTransport( 8764): User-Agent: android-kinvey-http/2.9.5

07-28 16:04:27.587 D/HttpTransport( 8764): x-kinvey-api-version: 3

07-28 16:04:27.587 D/HttpTransport( 8764): x-kinvey-device-information: Asus/Nexus_7 Android 4.2.2 0e0a9175-c3fc-37fc-b36e-0c6d65df3756

07-28 16:04:27.587 D/HttpTransport( 8764): Content-Type: application/json; charset=UTF-8

07-28 16:04:27.587 D/HttpTransport( 8764): Content-Length: 126

07-28 16:04:27.587 D/HttpTransport( 8764): curl -v --compressed -X POST -H 'Accept-Encoding: gzip' -H 'Authorization: <Not Logged>' -H 'Content-Type: application/json; charset=UTF-8' -H 'User-Agent: android-kinvey-http/2.9.5' -H 'x-kinvey-api-version: 3' -H 'x-kinvey-device-information: Asus/Nexus_7 Android 4.2.2 0e0a9175-c3fc-37fc-b36e-0c6d65df3756' -H 'Content-Type: application/json; charset=UTF-8' -d '@-' -- 'https://baas.kinvey.com/appdata/kid_-yj4pCgcq/00CCUAlerts/_group' << $$$

07-28 16:04:27.587 D/HttpTransport( 8764): Total: 126 bytes

07-28 16:04:27.587 D/HttpTransport( 8764): {"condition":{"is_fixed":false},"initial":{"_result":0},"key":{"severity":true},"reduce":"function(doc,out){ out._result++;}"}

07-28 16:04:27.957 D/HttpTransport( 8764): -------------- RESPONSE --------------

07-28 16:04:27.957 D/HttpTransport( 8764): 200 OK

07-28 16:04:27.957 D/HttpTransport( 8764): Content-Length: 166

07-28 16:04:27.957 D/HttpTransport( 8764): Content-Type: application/json; charset=utf-8

07-28 16:04:27.957 D/HttpTransport( 8764): Date: Tue, 28 Jul 2015 10:34:29 GMT

07-28 16:04:27.957 D/HttpTransport( 8764): Server: ngx_openresty

07-28 16:04:27.957 D/HttpTransport( 8764): X-Android-Received-Millis: 1438079667953

07-28 16:04:27.957 D/HttpTransport( 8764): X-Android-Sent-Millis: 1438079667594

07-28 16:04:27.957 D/HttpTransport( 8764): X-Kinvey-API-Version: 3

07-28 16:04:27.957 D/HttpTransport( 8764): X-Kinvey-Request-Id: 6aaec528b3a94fd58e6c1cbb3860f08e

07-28 16:04:27.957 D/HttpTransport( 8764): X-Powered-By: Express

07-28 16:04:27.957 D/HttpTransport( 8764): Total: 166 bytes

07-28 16:04:27.957 D/HttpTransport( 8764): [{"severity":"ERROR","_result":62},{"severity":"WARN","_result":86},{"severity":"INFO","_result":18},{"severity":"FATAL","_result":15},{"severity":"LOW","_result":1}]

07-28 16:04:27.957 E/Kinvey - Client( 8764): unable to parse response -> java.lang.IllegalArgumentException:

I did some more digging and it seems the issue comes when the response has a json array as part of the packet. The easiest way to get to the problem is to use the aggregation and grouping stuff on android. I can confirm that it works fine on iOS. 

Pankaj,


Can you give us some steps to reproduce this issue?


Thanks,

Using count function to do aggregation is the simplest way to reproduce it as that returns a json array as can be seen from the log I have added. The count function works fine on iOS, backbone, REST etc but fails with "unable to parse response" error on android. Can you confirm that count is working fine for you on android?


Thanks

Pankaj 

That always happens to me. If it carries on I have to stop using kinvey :/

Yasin,


Can you share the code that is causing you to experience this issue?


Thanks,

Hi,


I'm running into the exact same issue. Testing the code provided on the website I get this error when trying to fetch all:


D/dalvikvm: newInstance failed: no <init>()

D/dalvikvm: GC_CONCURRENT freed 1905K, 11% free 19253K/21511K, paused 11ms+0ms, total 21ms

D/OpenGLRenderer: TextureCache::get: create texture(0xb8dfe200): name, size, mSize = 176, 777600, 7995600

E/TAG: failed to fetch all

       com.kinvey.java.KinveyException:

       REASON: Unable to parse the JSON in the response

       FIX: examine BL or DLC to ensure data format is correct. If the exception is caused by `key <somkey>`, then <somekey> might be a different type than is expected (int instead of of string)

       EXPLANATION: java.lang.IllegalArgumentException:


Code below. 


If I use a non existing collection it returns 0 and there is no error.


Thanks.


 

final AsyncAppData<EventEntity> myevents = mKinveyClient.appData("Concerts", EventEntity.class);
myevents.get(new KinveyListCallback<EventEntity>() {

    
    @Override
    public void onSuccess(EventEntity[] result) {
        
        Log.v("TAG", "received "+ result.length + " events");
    }
    @Override
    public void onFailure(Throwable error)  {
        Log.e("TAG", "failed to fetch all", error);
    }
});
public class EventEntity extends GenericJson {
       @Key("_id")
      private String id;
        @Key("ConcertName")
        private String concertName;
        @Key("ConcertLink")
        private String concertLink;
        @Key("ImgLink")
        private String imgLink;
//        @Key("_kmd")
//        private KinveyMetaData meta; // Kinvey metadata, OPTIONAL
//        @Key("_acl")
//        private KinveyMetaData.AccessControlList acl; //Kinvey access control, OPTIONAL

        public EventEntity(){}  //GenericJson classes must have a public empty constructor

      }

 

Vitor, 


Can you enable debug mode as outlined in the troubleshooting guide in the devcenter http://devcenter.kinvey.com/android/guides/troubleshooting and let me see the requests that lead up to this issue.


Thanks,

Login or Signup to post a comment