2017-12-08 6 views
0

JSON을 제공하는 서버 레스트가 있습니다. Retrofit을 사용하여 사용자 목록은 아니지만 사용자는 얻을 수 있습니다.JSON 목록에 Retrofit으로 다른 객체가 임베드되어 있습니다.

사용자 JSON 예제 (서버/사용자/2) :

{ 
    "id": 2, 
    "firstName": "name", 
    "lastName": "name" 
} 

사용자 목록의 예 (서버/사용자) :

{ 
    "_embedded": { 
    "users": [ 
     { 
     "id": 2, 
     "firstName": "name", 
     "lastName": "name" 
     }, 
     { 
     "id": 3, 
     "firstName": "Ime", 
     "lastName": "Léonide" 
     } 
    ] 
    } 
} 

나는이 "_embedded"에 의해 발생 같아요. 나는 이것을 바꿀 수 있다고 생각하지 않는다.

자바 코드 :

@GET("users/") 
Call<List<User>> usersList(); 

답변

1

시도 :

@GET("users/") 
Call<UserResponse> usersList(); 

class UserResponse { 
    @SerializedName("_embedded") 
    UserList embedded; 
} 

class UserList { 
    @SerializedName("users") 
    List<User> userList; 
}