#631 - Partial Response : Get specified fields response.

This commit is contained in:
Gopinath Langote committed 2017-09-14 19:45:56 +05:30
1 parent d0ad0f7ea9
commit 6d3dce065d
4 files changed
+68 -6

No files matched your search

@@ -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);
}
}