-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdited.java
More file actions
48 lines (44 loc) · 1.7 KB
/
Edited.java
File metadata and controls
48 lines (44 loc) · 1.7 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
package io.quicktype;
import java.util.Map;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.*;
@JsonDeserialize(using = Edited.Deserializer.class)
@JsonSerialize(using = Edited.Serializer.class)
public class Edited {
public Double doubleValue;
public Boolean boolValue;
static class Deserializer extends JsonDeserializer<Edited> {
@Override
public Edited deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
Edited value = new Edited();
switch (jsonParser.getCurrentToken()) {
case VALUE_NUMBER_INT:
case VALUE_NUMBER_FLOAT:
value.doubleValue = jsonParser.readValueAs(Double.class);
break;
case VALUE_TRUE:
case VALUE_FALSE:
value.boolValue = jsonParser.readValueAs(Boolean.class);
break;
default: throw new IOException("Cannot deserialize Edited");
}
return value;
}
}
static class Serializer extends JsonSerializer<Edited> {
@Override
public void serialize(Edited obj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
if (obj.doubleValue != null) {
jsonGenerator.writeObject(obj.doubleValue);
return;
}
if (obj.boolValue != null) {
jsonGenerator.writeObject(obj.boolValue);
return;
}
throw new IOException("Edited must not be null");
}
}
}