Closed dreamsbond closed 6 years ago
Thanks for issuing the problem. The getContext
is replaced by getDocument
for clarity in 3.3.0. I've checked the CI to find it fails to build 3.3.0 due to some changes to the build environment.
I've requested another build for 3.3.1. It'll soon be available at bintray :-)
3.3.1 is available now 🎉
and how to get the relationship attributes as like as getting resource attributes?
mPlaceApi = BaseApi.getClient().create(PlacesApi.class);
Call<List<Place>> getPlaces = mPlacesApi.getPlaces();
getPlaces.enqueue(new Callback<List<Place>>() {
@Override
public void onResponse(Call<List<Place>> call, Response<List<Place>> response) {
mPlaces = response.body();
for (int i = 0; i < mPlaces.size(); i++) {
System.out.println(mPlaces.get(i).getId();
System.out.println(mPlaces.get(i).getName();
// how to get attributes from the relationship?
System.out.println(mPlaces.get(i).getPlaceType().getAttributeName());
}
}
@Override
public void onFailure(Call<List<Place>> call, Throwable t) {
}
});
thanks
How is the Place
implemented?
This is the Place Model
import com.squareup.moshi.Json;
import moe.banana.jsonapi2.HasOne;
import moe.banana.jsonapi2.JsonApi;
import moe.banana.jsonapi2.Resource;
@JsonApi(type = "places")
public class Place extends Resource {
private String name;
@Json(name = "created-at")
private String createdAt;
@Json(name = "updated-at")
private String updatedAt;
@Json(name = "deleted-at")
private String deletedAt;
@Json(name = "type")
public HasOne<PlaceType> placeType;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}
public String getDeletedAt() {
return deletedAt;
}
public void setDeletedAt(String deletedAt) {
this.deletedAt = deletedAt;
}
public HasOne<PlaceType> getPlaceType() {
return placeType;
}
public void setPlaceType(HasOne<PlaceType> placeType) {
this.placeType = placeType;
}
}
and this is PlaceType
import com.squareup.moshi.Json;
import moe.banana.jsonapi2.JsonApi;
import moe.banana.jsonapi2.Resource;
import moe.banana.jsonapi2.HasMany;
@JsonApi(type = "place-types")
public class PlaceType extends Resource {
private String name;
@Json(name = "created-at")
private String createdAt;
@Json(name = "updated-at")
private String updatedAt;
@Json(name = "deleted-at")
private String deletedAt;
private HasMany<Place> places;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}
public String getDeletedAt() {
return deletedAt;
}
public void setDeletedAt(String deletedAt) {
this.deletedAt = deletedAt;
}
public HasMany<Place> getPlaces() {
return places;
}
public void setPlaces(HasMany<Place> places) {
this.places = places;
}
}
Here's the example https://github.com/kamikat/moshi-jsonapi#relationships.
I have idea where to find the getDocument()
the getDocument() was a unresolved method.