-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonClass.java
More file actions
27 lines (22 loc) · 1004 Bytes
/
JsonClass.java
File metadata and controls
27 lines (22 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.ngcodex;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class JsonClass {
private static final ObjectMapper objectMapper = new ObjectMapper();
public static List<Map<String, Object>> parseJsonList(String json) {
try {
Map<String, Object> responseAsMap = objectMapper.readValue(json, new TypeReference<Map<String, Object>>() {});
return Collections.singletonList(responseAsMap);
} catch (IOException e) {
e.printStackTrace();
return Collections.emptyList();
}
}
public static Map<String, Object> parseJsonObject(String json) throws IOException {
return objectMapper.readValue(json, new TypeReference<Map<String, Object>>() {});
}
}