-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConverter.java
More file actions
161 lines (128 loc) · 5.34 KB
/
Converter.java
File metadata and controls
161 lines (128 loc) · 5.34 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// To use this code, add the following Maven dependency to your project:
//
// com.fasterxml.jackson.core : jackson-databind : 2.9.0
//
// Import this package:
//
// import io.quicktype.Converter;
//
// Then you can deserialize a JSON string with
//
// Map<String, String> data = Converter.APIDataFromJsonString(jsonString);
// Map<String, String> data = Converter.EmojisFromJsonString(jsonString);
// Events[] data = Converter.EventsFromJsonString(jsonString);
// Gists[] data = Converter.GistsFromJsonString(jsonString);
// Meta data = Converter.MetaFromJsonString(jsonString);
package io.quicktype;
import java.util.Map;
import java.io.IOException;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.core.JsonProcessingException;
public class Converter {
// Serialize/deserialize helpers
public static Map<String, String> APIDataFromJsonString(String json) throws IOException {
return getAPIDataObjectReader().readValue(json);
}
public static String APIDataToJsonString(Map<String, String> obj) throws JsonProcessingException {
return getAPIDataObjectWriter().writeValueAsString(obj);
}
public static Map<String, String> EmojisFromJsonString(String json) throws IOException {
return getEmojisObjectReader().readValue(json);
}
public static String EmojisToJsonString(Map<String, String> obj) throws JsonProcessingException {
return getEmojisObjectWriter().writeValueAsString(obj);
}
public static Events[] EventsFromJsonString(String json) throws IOException {
return getEventsObjectReader().readValue(json);
}
public static String EventsToJsonString(Events[] obj) throws JsonProcessingException {
return getEventsObjectWriter().writeValueAsString(obj);
}
public static Gists[] GistsFromJsonString(String json) throws IOException {
return getGistsObjectReader().readValue(json);
}
public static String GistsToJsonString(Gists[] obj) throws JsonProcessingException {
return getGistsObjectWriter().writeValueAsString(obj);
}
public static Meta MetaFromJsonString(String json) throws IOException {
return getMetaObjectReader().readValue(json);
}
public static String MetaToJsonString(Meta obj) throws JsonProcessingException {
return getMetaObjectWriter().writeValueAsString(obj);
}
private static ObjectReader APIDataReader;
private static ObjectWriter APIDataWriter;
private static void instantiateAPIDataMapper() {
ObjectMapper mapper = new ObjectMapper();
APIDataReader = mapper.reader(Map.class);
APIDataWriter = mapper.writerFor(Map.class);
}
private static ObjectReader getAPIDataObjectReader() {
if (APIDataReader == null) instantiateAPIDataMapper();
return APIDataReader;
}
private static ObjectWriter getAPIDataObjectWriter() {
if (APIDataWriter == null) instantiateAPIDataMapper();
return APIDataWriter;
}
private static ObjectReader EmojisReader;
private static ObjectWriter EmojisWriter;
private static void instantiateEmojisMapper() {
ObjectMapper mapper = new ObjectMapper();
EmojisReader = mapper.reader(Map.class);
EmojisWriter = mapper.writerFor(Map.class);
}
private static ObjectReader getEmojisObjectReader() {
if (EmojisReader == null) instantiateEmojisMapper();
return EmojisReader;
}
private static ObjectWriter getEmojisObjectWriter() {
if (EmojisWriter == null) instantiateEmojisMapper();
return EmojisWriter;
}
private static ObjectReader EventsReader;
private static ObjectWriter EventsWriter;
private static void instantiateEventsMapper() {
ObjectMapper mapper = new ObjectMapper();
EventsReader = mapper.reader(Events[].class);
EventsWriter = mapper.writerFor(Events[].class);
}
private static ObjectReader getEventsObjectReader() {
if (EventsReader == null) instantiateEventsMapper();
return EventsReader;
}
private static ObjectWriter getEventsObjectWriter() {
if (EventsWriter == null) instantiateEventsMapper();
return EventsWriter;
}
private static ObjectReader GistsReader;
private static ObjectWriter GistsWriter;
private static void instantiateGistsMapper() {
ObjectMapper mapper = new ObjectMapper();
GistsReader = mapper.reader(Gists[].class);
GistsWriter = mapper.writerFor(Gists[].class);
}
private static ObjectReader getGistsObjectReader() {
if (GistsReader == null) instantiateGistsMapper();
return GistsReader;
}
private static ObjectWriter getGistsObjectWriter() {
if (GistsWriter == null) instantiateGistsMapper();
return GistsWriter;
}
private static ObjectReader MetaReader;
private static ObjectWriter MetaWriter;
private static void instantiateMetaMapper() {
ObjectMapper mapper = new ObjectMapper();
MetaReader = mapper.reader(Meta.class);
MetaWriter = mapper.writerFor(Meta.class);
}
private static ObjectReader getMetaObjectReader() {
if (MetaReader == null) instantiateMetaMapper();
return MetaReader;
}
private static ObjectWriter getMetaObjectWriter() {
if (MetaWriter == null) instantiateMetaMapper();
return MetaWriter;
}
}