-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonParser.java
More file actions
34 lines (26 loc) · 903 Bytes
/
JsonParser.java
File metadata and controls
34 lines (26 loc) · 903 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
28
29
30
31
32
33
34
package ru.javaops.webapp.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import ru.javaops.webapp.model.AbstractSection;
import java.io.Reader;
import java.io.Writer;
public class JsonParser {
private static Gson GSON = new GsonBuilder()
.registerTypeAdapter(AbstractSection.class, new JsonSectionAdapter())
.create();
public static <T> T read(Reader reader, Class<T> clazz) {
return GSON.fromJson(reader, clazz);
}
public static <T> void write(T object, Writer writer) {
GSON.toJson(object, writer);
}
public static <T> T read(String value, Class<T> clazz) {
return GSON.fromJson(value, clazz);
}
public static <T> String write(T obj) {
return GSON.toJson(obj);
}
public static <T> String write(T object, Class<T> clazz) {
return GSON.toJson(object, clazz);
}
}