1

I have a class:

public class PetModel{
    Serialized("cat")
    String cat;
    Serialized("dog")
    String dog;
    // getters and setters
}

when I do a POST using retrofit like so:

@FormUrlEncoded
@POST("/pet/{id}")
Pets postPets(@Path("id") String id,@Field("pets") ArrayList<PetModel> pets);

In the logs I see the request sending <package_name>.PetModel@cc49e70 instead of sending the values itself. What am I doing wrong?

Metal
  • 143
  • 2
  • 9

3 Answers3

0

Please try bellow method, may be you will got solution

PrintWriter out = response.getWriter();
List<Countries> country = new ArrayList<Countries>();
country = FetchData.getAllCountries();
JSONObject js = new JSONObject();
js.put("countries", country); // make sure the Country class overrides toString()

// set the response content-type
response.setContentType("application/json");

// writing the json-array to the output stream
out.print(js.toJSONString());
out.flush();
shekhar pande
  • 1,172
  • 1
  • 11
  • 21
0

If you have access to the server side code and can change it just add a viewmodel or something as a class containing the array list of generic type T. Then every where of working with arraylists use that.

There is similar problem when retrieving String type from server which can be solved same way.

ConductedClever
  • 4,175
  • 2
  • 35
  • 69
0

Override toString() method from your PetModel class.

public class PetModel {
    Serialized("cat")
    String cat;
    Serialized("dog")
    String dog;
    // getters and setters

    @Override
    public String toString() {
        return "Cat " + cat + " Dog " + dog; 
    }
}
Cătălin Florescu
  • 5,012
  • 1
  • 25
  • 36