mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-12 10:13:46 +00:00
#631 - Partial Response : Get specified fields response.
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user