forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReflectionDecoderFactory.java
More file actions
34 lines (31 loc) · 1.12 KB
/
ReflectionDecoderFactory.java
File metadata and controls
34 lines (31 loc) · 1.12 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
package com.jsoniter;
import com.jsoniter.spi.Decoder;
import com.jsoniter.spi.TypeLiteral;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Map;
public class ReflectionDecoderFactory {
public static Decoder create(Class clazz, Type... typeArgs) {
final TypeLiteral typeLiteral = TypeLiteral.create(clazz);
TypeLiteral.NativeType nativeType = typeLiteral.getNativeType();
if (nativeType != null) {
return new Decoder() {
@Override
public Object decode(JsonIterator iter) throws IOException {
return CodegenAccess.read(iter, typeLiteral);
}
};
}
if (clazz.isArray()) {
return new ReflectionArrayDecoder(clazz);
}
if (Collection.class.isAssignableFrom(clazz)) {
return new ReflectionCollectionDecoder(clazz, typeArgs);
}
if (Map.class.isAssignableFrom(clazz)) {
return new ReflectionMapDecoder(clazz, typeArgs);
}
return new ReflectionObjectDecoder(clazz).create();
}
}