#631 - Partial Response : Get specified fields response.

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

View File

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