Android Retrofit object is null - android

I'm using retrofit for a network request, but I found a very weird situation, so for some reason my object inside of the array always is null, but other properties are correct.
https://i.stack.imgur.com/pmlh7.jpg
https://i.stack.imgur.com/qBDFQ.png
Logs form okhttp:
https://i.stack.imgur.com/I74Wp.png

Related

Get response from Retrofit with suspend method for generic objects with Kotlin

I have a generic method getData that should get from the server some POJOs of different objects. Before Retrofit 2.6 without coroutines I could create a method like this:
#POST("GetData")
fun getGenericData(#Query("sessionId") sessionId: UUID, #Body request: RemoteRequest): Call<ResponseBody>
An it was fine because I could handle the json contained in the body and deserialize it based on the object name declared in a property inside the json, but with Retrofit 2.6 and coroutines that is not possibile because the return type Call or ResponseBody throw an exception. I do not want to use Response because I do not know the type of the object at compile time and I want to deserialize the returned json separately. Any idea ?

'error=''unicode' object has no attribute 'items''

I am making a POST request using Retrofit, call executes successfully on rest client. Also onResponse of call executes but in response body i am getting error
'unicode' object has no attribute 'items'.
What is the reason of this error?

Parsing Nested Json Object with Retrofit

I'm using Retrofit to parse a JSON returned by the API in this link using POJO Model Classes as mentioned in Retrofit Documentation I use asynchronous method to successfully get the tags inside "entities". However, when I try to get the "profile" tag from the "Media", I get a Null pointer exception and the App crashes.
I tried printing the "Profile" data from Media tag to the LogCat, the App crashes but I can see the URL string printed in LogCat along with Null Pointer Exception for the same method.
This is confusing as my method returns the mapped Data from API but, still shows Null Pointer Exception.

Retrofit / Robospice handle multiple response objects

How do I make Retrofit / Robospice handle my api responses in a way that I can get an empty JSON response body like: {}, but also a regular JSON response body?
Currently the empty response body initialises a new POJO, but I only want this to happen if there is actually a filled response body.
I have an object that contains three booleans, and these will always be set to false, while this shouldn't happen.
I somehow have the idea this is caused by my GSON deserializer (I use the default one), but don't know where to start for something like this.
Thanks for any help. :)
Why not using Boolean instead of boolean? That way the default value in null rather than false
Retrofit doesn't touch fields if there's no such fields in json. So init them by yourself.
public class Response {
public boolean value = true;
}

How to handle non-2XX response codes in RoboSpice?

In my API server returns HTTP 400 response code if request does not pass validation, and provides detailed message, that should be parsed as the response.
For example:
public class RegistrationResponse {
private String emailError; // Detailed message. Null if no error occured
}
But Robospice (Retrofit + OkHttp) fires onRequestFailure() with message "retrofit.RetrofitError: 400 BAD REQUEST" in this case and, of course, does not parse anything.
How should I make it parse the response in case if response code is not 2XX?
You should declare Retrofit methods that return HTTP Response objects and check the raw object in your loadDataFromNetwork() for the status you need. This way, however, you will skip the out-of-the-box functionality of parsing responses and will have to do that manually.
Therefore, you should also find a way to reuse the Converter passed to your RestAdapter in the RetrofitSpiceService. Overriding the RetrofitSpiceService#createConverter() method is probably the simplest way to achieve this.

Categories

Resources