SimpleRESTClientHandler
SimpleRESTClientHandler copied to clipboard
Cannot pass Serializable objects in bundle while placing API call
I am working on a project with this library. I have an API call that accepts the following payload
{
"first_name": "Mohit",
"age": 27,
"address": {
"line1": "abc",
"line2": "def",
"pincode": 400000
}
}
So, my User
Object here has another Serializable
Object called Address
. I am unable to pass the model as it is in the Bundle by using the following snippet.
Bundle bundle = new Bundle();
bundle.putString("first_name", user.getFirstName());
bundle.putInt("age", user.getAge());
bundle.putSerializable("address", user.getAddress());
The API always gives 503 since the convertToJSON
method in the BundleJSONConverter
class gives "Unsupported type"
exception always because the recursive call makes the class makes the Setter
null as the Address
object is not a List<T>
or a Bundle
.
Can you please fix this? Or suggest a workaround.
Hi @mohitajwani why aren't you serializing your user class?
Hi @mohitajwani , as @joaquinlateral you could have a DTO (Data Transfer Object) Class and pass it as parameter instead of using a Bundle object.
For example:
public class UpdateUser {
@SerializedName("first_name")
String firstName;
@SerializedName("age")
int age;
@SerializedName("address")
Address address;
}
@joaquinlateral @julianfalcionelli I am already Serializing my class, but still getting the mentioned issue.
The actual code has 2 models to be sent in one Request. Both models are in 2 different classes.
@mohitajwani I understand but then there is a problem in how you're sending classes and how your code has been modeled. This is not an issue of the library.
Did u try what I put above?, passing a DTO object instead of using a bundle?