MCPcopy Create free account
hub / github.com/e2wugui/zeze / Json

Class Json

ZezeJava/ZezeJava/src/main/java/Zeze/Util/Json.java:25–1303  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24// Compile with JDK11+; Run with JDK8+ (JDK9+ is recommended); Android is NOT supported
25public final class Json implements Cloneable {
26 static final int TYPE_BOOLEAN = 1; // boolean, Boolean
27 static final int TYPE_BYTE = 2; // byte, Byte
28 static final int TYPE_SHORT = 3; // short, Short
29 static final int TYPE_CHAR = 4; // char, Character
30 static final int TYPE_INT = 5; // int, Integer
31 static final int TYPE_LONG = 6; // long, Long
32 static final int TYPE_FLOAT = 7; // float, Float
33 static final int TYPE_DOUBLE = 8; // double, Double
34 static final int TYPE_STRING = 9; // String
35 static final int TYPE_OBJECT = 10; // Object(null,Boolean,Integer,Long,Double,String,ArrayList<?>,HashMap<?,?>)
36 static final int TYPE_POS = 11; // Pos(pos)
37 static final int TYPE_CUSTOM = 12; // user custom type
38 static final int TYPE_WRAP_FLAG = 0x10; // wrap<1~8>
39 static final int TYPE_LIST_FLAG = 0x20; // Collection<1~12> (parser only needs clear() & add(v))
40 static final int TYPE_MAP_FLAG = 0x30; // Map<String, 1~12> (parser only needs clear() & put(k,v))
41
42 public interface KeyReader {
43 @NotNull Object parse(@NotNull JsonReader jr, int b) throws ReflectiveOperationException;
44 }
45
46 public interface Creator<T> {
47 T create() throws ReflectiveOperationException;
48 }
49
50 public static final class FieldMeta {
51 public final int hash; // for FieldMetaMap
52 public final int type; // defined above
53 public final int offset; // for unsafe access
54 public final @NotNull Class<?> klass; // TYPE_CUSTOM:fieldClass; TYPE_LIST_FLAG/TYPE_MAP_FLAG:subValueClass
55 transient @Nullable ClassMeta<?> classMeta; // from klass, lazy assigned
56 transient @Nullable FieldMeta next; // for FieldMetaMap
57 public final byte[] name; // field name
58 public final @Nullable Creator<?> ctor; // for TYPE_LIST_FLAG/TYPE_MAP_FLAG
59 public final @Nullable KeyReader keyParser; // for TYPE_MAP_FLAG
60 public final @NotNull Field field;
61 public final @Nullable Type[] paramTypes;
62
63 public FieldMeta(int type, int offset, @NotNull String name, @NotNull Class<?> klass, @Nullable Creator<?> ctor,
64 @Nullable KeyReader keyReader, @NotNull Field field) {
65 this.name = name.getBytes(StandardCharsets.UTF_8);
66 this.hash = getKeyHash(this.name, 0, this.name.length);
67 this.type = type;
68 this.offset = offset;
69 this.klass = klass;
70 this.ctor = ctor;
71 this.keyParser = keyReader;
72 this.field = field;
73 Type geneType = field.getGenericType();
74 paramTypes = geneType instanceof ParameterizedType
75 ? ((ParameterizedType)geneType).getActualTypeArguments() : null;
76 }
77
78 public @NotNull String getName() {
79 return new String(name, StandardCharsets.UTF_8);
80 }
81 }
82

Callers

nothing calls this directly

Calls 15

getDeclaredFieldMethod · 0.95
setAccessibleMethod · 0.95
ensureNotNullMethod · 0.95
objectFieldOffsetMethod · 0.95
WrapMethod · 0.95
parseIntegerKeyMethod · 0.95
parseLongKeyMethod · 0.95
getPropertyMethod · 0.80
getMethodMethod · 0.80
requireNonNullMethod · 0.80
setParserMethod · 0.80
getClassMetaMethod · 0.80

Tested by

no test coverage detected