-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeType.java
More file actions
47 lines (41 loc) · 1.25 KB
/
NodeType.java
File metadata and controls
47 lines (41 loc) · 1.25 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
package game.slam.util.animation.data;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
public enum NodeType {
BONE,
STRUCT,
CAMERA,
LOCATOR,
TEXT_DISPLAY,
ITEM_DISPLAY,
BLOCK_DISPLAY,
UNKNOWN;
/**
* Type adapter to teach Gson builder how to serialize/deserialize this object type
*/
public static class TypeAdapter extends com.google.gson.TypeAdapter<NodeType> {
@Override
public void write(JsonWriter out, NodeType value) throws IOException {
if (value == null) {
out.nullValue();
} else {
out.value(value.name().toLowerCase());
}
}
@Override
public NodeType read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
String stringValue = in.nextString();
try {
return valueOf(stringValue.toUpperCase());
} catch (IllegalArgumentException e) {
return UNKNOWN;
}
}
}
}