#631 - Partial Response : Get specified fields response.
This commit is contained in:
@@ -27,13 +27,18 @@ package com.iluwatar.partialresponse;
|
||||
import java.util.Map;
|
||||
|
||||
public class VideoResource {
|
||||
private FieldJsonMapper fieldJsonMapper;
|
||||
private Map<Integer, Video> videos;
|
||||
|
||||
public VideoResource(Map<Integer, Video> videos) {
|
||||
public VideoResource(FieldJsonMapper fieldJsonMapper, Map<Integer, Video> videos) {
|
||||
this.fieldJsonMapper = fieldJsonMapper;
|
||||
this.videos = videos;
|
||||
}
|
||||
|
||||
public String getDetails(Integer id) {
|
||||
return videos.get(id).toString();
|
||||
public String getDetails(Integer id, String... fields) {
|
||||
if (fields.length == 0) {
|
||||
return videos.get(id).toString();
|
||||
}
|
||||
return fieldJsonMapper.toJson(videos.get(id), fields);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user