-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJsonFormat.java
More file actions
125 lines (97 loc) · 3.71 KB
/
Copy pathJsonFormat.java
File metadata and controls
125 lines (97 loc) · 3.71 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
package fr.maif.json;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.node.ArrayNode;
import tools.jackson.databind.node.ObjectNode;
import io.vavr.collection.List;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* A combinaison on JsonRead and JsonWrite.
*
* @param <T>
*/
public interface JsonFormat<T> extends JsonRead<T>, JsonWrite<T> {
JsonRead<T> jsonRead();
JsonWrite<T> jsonWrite();
static <T> JsonFormat<T> of(JsonRead<T> read, JsonWrite<T> write) {
return new JsonFormat<>() {
@Override
public JsonRead<T> jsonRead() {
return read;
}
@Override
public JsonWrite<T> jsonWrite() {
return write;
}
@Override
public JsResult<T> read(JsonNode jsonNode) {
return read.read(jsonNode);
}
@Override
public JsonSchema jsonSchema() {
return read.jsonSchema();
}
@Override
public JsonNode write(T value) {
return write.write(value);
}
};
}
static <T> JsonFormat<T> _$fromClass(Class<T> clazz) {
return JsonFormat.of(JsonRead._fromClass(clazz), JsonWrite.auto());
}
static <T> JsonFormat<T> _$fromClass(TypeReference<T> clazz) {
return JsonFormat.of(JsonRead._fromClass(clazz), JsonWrite.auto());
}
static <T> JsonFormat<List<T>> _$list(JsonFormat<T> format) {
return JsonFormat.of(JsonRead._list(format), JsonWrite.$list(format));
}
static <T> JsonFormat<ArrayNode> _$jsonArray() {
return JsonFormat.of(JsonRead._jsonArray(), JsonWrite.$jsonArray());
}
static <T> JsonFormat<ObjectNode> _$jsonObject() {
return JsonFormat.of(JsonRead._jsonObject(), JsonWrite.$jsonObject());
}
static <T> JsonFormat<JsonNode> _$json() {
return JsonFormat.of(JsonRead._json(), it -> it);
}
static JsonFormat<String> _$string() {
return JsonFormat.of(JsonRead._string(), JsonWrite.$string());
}
static JsonFormat<Integer> _$int() {
return JsonFormat.of(JsonRead._int(), JsonWrite.$int());
}
static JsonFormat<Long> _$long() {
return JsonFormat.of(JsonRead._long(), JsonWrite.$long());
}
static JsonFormat<Double> _$double() {
return JsonFormat.of(JsonRead._double(), JsonWrite.$double());
}
static JsonFormat<Float> _$float() {
return JsonFormat.of(JsonRead._float(), JsonWrite.$float());
}
static JsonFormat<BigDecimal> _$bigDecimal() {
return JsonFormat.of(JsonRead._bigDecimal(), JsonWrite.$bigdecimal());
}
static JsonFormat<LocalDate> _$localDate(DateTimeFormatter formatter) {
return JsonFormat.of(JsonRead._localDate(formatter), JsonWrite.$localdate(formatter));
}
static JsonFormat<LocalDate> _$isoLocalDate() {
return JsonFormat.of(JsonRead._isoLocalDate(), JsonWrite.$localdate());
}
static JsonFormat<LocalDateTime> _$localDateTime(DateTimeFormatter formatter) {
return JsonFormat.of(JsonRead._localDateTime(formatter), JsonWrite.$localdatetime(formatter));
}
static JsonFormat<LocalDateTime> _$isoLocalDateTime() {
return JsonFormat.of(JsonRead._isoLocalDateTime(), JsonWrite.$localdatetime());
}
static JsonFormat<Boolean> _$boolean() {
return JsonFormat.of(JsonRead._boolean(), JsonWrite.$boolean());
}
static <E extends Enum<E>> JsonFormat<E> _$enum(Class<E> clazz) {
return JsonFormat.of(JsonRead._enum(clazz), JsonWrite.$enum());
}
}