I implement a retrofit 2 interface for analyzing JSON elements (videos, thumbnails, title, etc.).
JSONschema2Pojo led to 4 pojo classes, but the main / root is VideoInfo (it doesn't matter, implements Parcelable, I still do nothing with it) Does the disadvantage @SerializedName("....")affect anything, knowing that it is automatically generated by jsonschema2pojo? UPDATE: new pojo classes are generated, this time with Gson annotations (@SerializedName("") and @Expose), but with the same problem.
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.List;
public class VideoInfo implements Parcelable {
private List<Item> items = new ArrayList<Item>();
private int pageNumber;
private int pageSize;
private int totalCount;
public VideoInfo() {
}
public VideoInfo(List<Item> items, int pageNumber, int pageSize, int totalCount) {
this.items = items;
this.pageNumber = pageNumber;
this.pageSize = pageSize;
this.totalCount = totalCount;
}
public List<Item> getItems() {
return items;
}
public void setItems(List<Item> items) {
this.items = items;
}
public int getPageNumber() {
return pageNumber;
}
public void setPageNumber(int pageNumber) {
this.pageNumber = pageNumber;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
}
}
UPDATE : in the VideoInfo class above you can see private List<Item> items = new ArrayList<Item>();, this is because there is another pojo class that has a list of tim, as follows:
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;
public class Item {
@SerializedName("id")
@Expose
private int id;
@SerializedName("name")
@Expose
private String name;
@SerializedName("shortDescription")
@Expose
private String shortDescription;
@SerializedName("creationDate")
@Expose
private String creationDate;
@SerializedName("publishedDate")
@Expose
private String publishedDate;
@SerializedName("linkURL")
@Expose
private String linkURL;
@SerializedName("linkText")
@Expose
private String linkText;
@SerializedName("tags")
@Expose
private List<String> tags = new ArrayList<String>();
@SerializedName("videoStillURL")
@Expose
private String videoStillURL;
@SerializedName("thumbnailURL")
@Expose
private String thumbnailURL;
@SerializedName("length")
@Expose
private int length;
@SerializedName("renditions")
@Expose
private List<Rendition> renditions = new ArrayList<Rendition>();
@SerializedName("IOSRenditions")
@Expose
private List<IOSRendition> IOSRenditions = new ArrayList<IOSRendition>();
@SerializedName("HDSRenditions")
@Expose
private List<Object> HDSRenditions = new ArrayList<Object>();
public Item() {
}
public Item(int id, String name, String shortDescription, String creationDate, String publishedDate, String linkURL, String linkText, List<String> tags, String videoStillURL, String thumbnailURL, int length, List<Rendition> renditions, List<IOSRendition> IOSRenditions, List<Object> HDSRenditions) {
this.id = id;
this.name = name;
this.shortDescription = shortDescription;
this.creationDate = creationDate;
this.publishedDate = publishedDate;
this.linkURL = linkURL;
this.linkText = linkText;
this.tags = tags;
this.videoStillURL = videoStillURL;
this.thumbnailURL = thumbnailURL;
this.length = length;
this.renditions = renditions;
this.IOSRenditions = IOSRenditions;
this.HDSRenditions = HDSRenditions;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getShortDescription() {
return shortDescription;
}
public void setShortDescription(String shortDescription) {
this.shortDescription = shortDescription;
}
public String getCreationDate() {
return creationDate;
}
public void setCreationDate(String creationDate) {
this.creationDate = creationDate;
}
public String getPublishedDate() {
return publishedDate;
}
public void setPublishedDate(String publishedDate) {
this.publishedDate = publishedDate;
}
public String getLinkURL() {
return linkURL;
}
public void setLinkURL(String linkURL) {
this.linkURL = linkURL;
}
public String getLinkText() {
return linkText;
}
public void setLinkText(String linkText) {
this.linkText = linkText;
}
public List<String> getTags() {
return tags;
}
public void setTags(List<String> tags) {
this.tags = tags;
}
public String getVideoStillURL() {
return videoStillURL;
}
public void setVideoStillURL(String videoStillURL) {
this.videoStillURL = videoStillURL;
}
public String getThumbnailURL() {
return thumbnailURL;
}
public void setThumbnailURL(String thumbnailURL) {
this.thumbnailURL = thumbnailURL;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public List<Rendition> getRenditions() {
return renditions;
}
public void setRenditions(List<Rendition> renditions) {
this.renditions = renditions;
}
public List<IOSRendition> getIOSRenditions() {
return IOSRenditions;
}
public void setIOSRenditions(List<IOSRendition> IOSRenditions) {
this.IOSRenditions = IOSRenditions;
}
public List<Object> getHDSRenditions() {
return HDSRenditions;
}
public void setHDSRenditions(List<Object> HDSRenditions) {
this.HDSRenditions = HDSRenditions;
}
}
UPDATE. , , private List<Rendition> renditions = new ArrayList<Rendition>();, pojo. Rendition.class:
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Rendition {
@SerializedName("audioOnly")
@Expose
private boolean audioOnly;
@SerializedName("controllerType")
@Expose
private String controllerType;
@SerializedName("displayName")
@Expose
private String displayName;
@SerializedName("encodingRate")
@Expose
private int encodingRate;
@SerializedName("frameHeight")
@Expose
private int frameHeight;
@SerializedName("frameWidth")
@Expose
private int frameWidth;
@SerializedName("id")
@Expose
private int id;
@SerializedName("referenceId")
@Expose
private Object referenceId;
@SerializedName("remoteStreamName")
@Expose
private Object remoteStreamName;
@SerializedName("remoteUrl")
@Expose
private Object remoteUrl;
@SerializedName("size")
@Expose
private int size;
@SerializedName("uploadTimestampMillis")
@Expose
private int uploadTimestampMillis;
@SerializedName("url")
@Expose
private String url;
@SerializedName("videoCodec")
@Expose
private String videoCodec;
@SerializedName("videoContainer")
@Expose
private String videoContainer;
@SerializedName("videoDuration")
@Expose
private int videoDuration;
public Rendition() {
}
public Rendition(boolean audioOnly, String controllerType, String displayName, int encodingRate, int frameHeight, int frameWidth, int id, Object referenceId, Object remoteStreamName, Object remoteUrl, int size, int uploadTimestampMillis, String url, String videoCodec, String videoContainer, int videoDuration) {
this.audioOnly = audioOnly;
this.controllerType = controllerType;
this.displayName = displayName;
this.encodingRate = encodingRate;
this.frameHeight = frameHeight;
this.frameWidth = frameWidth;
this.id = id;
this.referenceId = referenceId;
this.remoteStreamName = remoteStreamName;
this.remoteUrl = remoteUrl;
this.size = size;
this.uploadTimestampMillis = uploadTimestampMillis;
this.url = url;
this.videoCodec = videoCodec;
this.videoContainer = videoContainer;
this.videoDuration = videoDuration;
}
public boolean isAudioOnly() {
return audioOnly;
}
public void setAudioOnly(boolean audioOnly) {
this.audioOnly = audioOnly;
}
public String getControllerType() {
return controllerType;
}
public void setControllerType(String controllerType) {
this.controllerType = controllerType;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public int getEncodingRate() {
return encodingRate;
}
public void setEncodingRate(int encodingRate) {
this.encodingRate = encodingRate;
}
public int getFrameHeight() {
return frameHeight;
}
public void setFrameHeight(int frameHeight) {
this.frameHeight = frameHeight;
}
public int getFrameWidth() {
return frameWidth;
}
public void setFrameWidth(int frameWidth) {
this.frameWidth = frameWidth;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Object getReferenceId() {
return referenceId;
}
public void setReferenceId(Object referenceId) {
this.referenceId = referenceId;
}
public Object getRemoteStreamName() {
return remoteStreamName;
}
public void setRemoteStreamName(Object remoteStreamName) {
this.remoteStreamName = remoteStreamName;
}
public Object getRemoteUrl() {
return remoteUrl;
}
public void setRemoteUrl(Object remoteUrl) {
this.remoteUrl = remoteUrl;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public int getUploadTimestampMillis() {
return uploadTimestampMillis;
}
public void setUploadTimestampMillis(int uploadTimestampMillis) {
this.uploadTimestampMillis = uploadTimestampMillis;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getVideoCodec() {
return videoCodec;
}
public void setVideoCodec(String videoCodec) {
this.videoCodec = videoCodec;
}
public String getVideoContainer() {
return videoContainer;
}
public void setVideoContainer(String videoContainer) {
this.videoContainer = videoContainer;
}
public int getVideoDuration() {
return videoDuration;
}
public void setVideoDuration(int videoDuration) {
this.videoDuration = videoDuration;
}
}
VideoInterface.class
import retrofit2.Call;
import retrofit2.http.GET;
public interface VideoInterface {
String apiURL = ".....";
@GET(apiURL)
public Call<VideosResponse> listVideos();
}
/ VideoResponse.java
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.ArrayList;
import java.util.List;
public class VideosResponse {
List<VideoInfo> videos;
public VideosResponse() {
videos = new ArrayList<VideoInfo>();
}
public static VideosResponse parseJSON(String response) {
Gson gson = new GsonBuilder().create();
VideosResponse videosResponse = gson.fromJson(response, VideosResponse.class);
return videosResponse;
}
}
: , API,
, - response.body().getItem().getID().getRendition().getUrl(), , , .
onResume(), public static , onResume()
final String BASE_URL = "http://api......";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
VideoInterface service = retrofit.create(VideoInterface.class);
Call<VideosResponse> call = service.listVideos();
call.enqueue(new Callback<VideosResponse>() {
@Override
public void onResponse(Call<VideosResponse> call, Response<VideosResponse> response) {
VideosResponse videoResponse = response.body();
}
@Override
public void onFailure(Call<VideosResponse> call, Throwable t) {
}});
, , ( ), :
Log.d("Videos ", response.message());
Log.d("Videos ", String.valueOf(response.isSuccess()));
Log.d("Videos ", String.valueOf(response.code()));
. , VideosResponse videoResponse = response.body();, : VideosResponse @3b8bfaa4, ? ?
? -?