質問編集履歴
3
呼び出し元のコードを追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -106,4 +106,34 @@
|
|
106
106
|
{
|
107
107
|
"created_time": "1446716528",
|
108
108
|
~
|
109
|
+
```
|
110
|
+
|
111
|
+
以下呼び出し元
|
112
|
+
|
113
|
+
```java
|
114
|
+
public クラスA Access(String url) throws IOException {
|
115
|
+
クラスA instagramData;
|
116
|
+
try {
|
117
|
+
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
|
118
|
+
GenericUrl genericUrl = new GenericUrl(url);
|
119
|
+
HttpRequest req = requestFactory.buildGetRequest(genericUrl);
|
120
|
+
HttpResponse res = req.execute();
|
121
|
+
|
122
|
+
try {
|
123
|
+
instagramData = asInstagramObject(res.parseAsString());
|
124
|
+
} finally {
|
125
|
+
res.disconnect();
|
126
|
+
}
|
127
|
+
} finally {
|
128
|
+
httpTransport.shutdown();
|
129
|
+
}
|
130
|
+
return instagramData;
|
131
|
+
}
|
132
|
+
|
133
|
+
// Json文字列をInstagramObjectに変換
|
134
|
+
private クラスA asInstagramObject(String stringJson) throws IOException {
|
135
|
+
ObjectMapper mapper = new ObjectMapper();
|
136
|
+
クラスA json = mapper.readValue(stringJson, クラスA.class);
|
137
|
+
return json;
|
138
|
+
}
|
109
139
|
```
|
2
表題がふさわしくなかったため
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
LinkedHashMapを指定クラスに
|
1
|
+
LinkedHashMapを指定クラスにキャスト出来ない
|
body
CHANGED
File without changes
|
1
swordone様からのご指摘により、記載するコードを増設しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -20,15 +20,46 @@
|
|
20
20
|
@Key("attribution")
|
21
21
|
private Object attribution;
|
22
22
|
@Key("tags")
|
23
|
+
private List<String> tsgs;
|
24
|
+
@Key("type")
|
25
|
+
private String type;
|
26
|
+
@Key("location")
|
27
|
+
private Object location;
|
28
|
+
@Key("comments")
|
29
|
+
private HashMap<String, Object> comments;
|
30
|
+
@Key("filter")
|
31
|
+
private Object filter;
|
32
|
+
@Key("created_time")
|
33
|
+
private Object created_time;
|
34
|
+
@Key("link")
|
35
|
+
private String link;
|
36
|
+
@Key("likes")
|
37
|
+
private HashMap<String, Object> likes;
|
38
|
+
@Key("images")
|
39
|
+
private HashMap<String, Object> images;
|
40
|
+
@Key("users_in_photo")
|
41
|
+
private Object users_in_photo;
|
42
|
+
@Key("caption")
|
43
|
+
private HashMap<String, Object> caption;
|
44
|
+
@Key("user_has_liked")
|
45
|
+
private Object user_has_liked;
|
46
|
+
@Key("id")
|
23
|
-
|
47
|
+
private String id;
|
48
|
+
@Key("user")
|
49
|
+
private HashMap<String, String> user;
|
24
50
|
}
|
25
51
|
```
|
26
52
|
|
27
53
|
実行したところ、下記拡張forでエラーになります。
|
28
54
|
|
29
55
|
```java
|
56
|
+
public List<HashMap<String, Object>> getInstagramImageData() {
|
57
|
+
List<HashMap<String, Object>> instagramImageList = new ArrayList<>();
|
58
|
+
|
30
59
|
for (DataBreakdown oneData : data) {
|
60
|
+
HashMap<String, Object> instagramImageData = new HashMap<>();
|
61
|
+
instagramImageData.put("images", oneData.getImages());
|
31
|
-
|
62
|
+
instagramImageList.add(instagramImageData);
|
32
63
|
}
|
33
64
|
return instagramImageList;
|
34
65
|
}
|