It comes to me from a JSON server of this format:

{"user":[{"username":"admin", "name":"Administrator", "email":"admin@example.com", "properties": {"property": {"@key":"console.order" ,"@value":"session-summary=0"}}}, {"username":"alice", "name":"Alice", "email":"alice@abc.com" ,"properties":null}]} 

I get an error in the getUsers () method, namely: java.io.IOException: unexpected end of stream on okhttp3.Address

and Caused by: java.io.EOFException: \n not found: size=0 content=. I can not understand what this error can be caused by? and how to fix it?

If in User class, I use String properties, instead of Properties properties, then I get the error: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT

getUsers() method:

  private void getUsers() { String credentials = "admin" + ":" + "admin"; final String basic = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); String contentType = "application/json"; String accept = "application/json"; Subscription subscription = App.service.users(basic, contentType, accept) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(users -> { contacts.addAll(users); Log.e("Users", users.toString()); contactAdapter.notifyDataSetChanged(); }, throwable -> { }); addSubscription(subscription); } 

API itself:

 public interface MessengerApi { @GET("users") Observable<List<User>> users(@Header("Authorization") String auth, @Header("Content-type") String contentType, @Header("Accept") String accept); } 

User class:

 public class User { @SerializedName("username") String username; @SerializedName("name") String name; @SerializedName("email") String email; @SerializedName("properties") private Properties properties; public User(String username, String name, String email, Properties properties) { this.username = username; this.name = name; this.email = email; this.properties = properties; } } 

Properties class:

 public class Properties { @SerializedName("property") private Property property; public Property getProperty() { return property; } } 

Property class:

 public class Property { @SerializedName("@key") private String key; @SerializedName("@value") private String value; public Property(String key, String value) { this.key = key; this.value = value; } public Property(String key) { this.key = key; } 

    1 answer 1

    Added Users class:

     public class Users { @SerializedName("user") List<User> user; //getters and setters } 

    Changed the code in the API:

     @GET("users") Observable<Users> users(@Header("Authorization") String auth, @Header("Content-type") String contentType, @Header("Accept") String accept); 

    After that it worked.