Skip to content

Commit 1d7597e

Browse files
committed
output support annotation
1 parent 8f6305b commit 1d7597e

26 files changed

+420
-82
lines changed

demo/src/main/java/com/jsoniter/demo/DemoCodegenConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.jsoniter.StaticCodeGenerator;
55
import com.jsoniter.spi.CodegenConfig;
66
import com.jsoniter.spi.Decoder;
7-
import com.jsoniter.spi.ExtensionManager;
7+
import com.jsoniter.spi.JsoniterSpi;
88
import com.jsoniter.spi.TypeLiteral;
99

1010
import java.io.IOException;
@@ -17,7 +17,7 @@ public class DemoCodegenConfig implements CodegenConfig {
1717
public void setup() {
1818
// register custom decoder or extensions before codegen
1919
// so that we doing codegen, we know in which case, we need to callback
20-
ExtensionManager.registerPropertyDecoder(User.class, "score", new Decoder.IntDecoder() {
20+
JsoniterSpi.registerPropertyDecoder(User.class, "score", new Decoder.IntDecoder() {
2121
@Override
2222
public int decodeInt(JsonIterator iter) throws IOException {
2323
return Integer.valueOf(iter.readString());

demo/src/test/java/com/jsoniter/demo/ConstructorBinding.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import com.jsoniter.JsonIterator;
1111
import com.jsoniter.ReflectionDecoderFactory;
1212
import com.jsoniter.annotation.JacksonAnnotationSupport;
13-
import com.jsoniter.spi.ExtensionManager;
13+
import com.jsoniter.spi.JsoniterSpi;
1414
import com.jsoniter.spi.TypeLiteral;
1515
import org.junit.Test;
1616
import org.openjdk.jmh.Main;
@@ -72,15 +72,15 @@ public void benchSetup(BenchmarkParams params) {
7272
JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_STRICTLY);
7373
}
7474
if (params.getBenchmark().contains("withJsoniterReflection")) {
75-
ExtensionManager.registerTypeDecoder(TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
75+
JsoniterSpi.registerTypeDecoder(TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
7676
}
7777
}
7878
}
7979

8080
@Test
8181
public void test() throws IOException {
8282
benchSetup(null);
83-
ExtensionManager.registerTypeDecoder(TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
83+
JsoniterSpi.registerTypeDecoder(TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
8484
System.out.println(withJsoniter());
8585
System.out.println(withJackson());
8686
}

demo/src/test/java/com/jsoniter/demo/PrivateFieldBinding.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.jsoniter.ReflectionDecoderFactory;
99
import com.jsoniter.annotation.JacksonAnnotationSupport;
1010
import com.jsoniter.spi.EmptyExtension;
11-
import com.jsoniter.spi.ExtensionManager;
11+
import com.jsoniter.spi.JsoniterSpi;
1212
import com.jsoniter.spi.ParameterizedTypeImpl;
1313
import com.jsoniter.spi.TypeLiteral;
1414
import org.junit.Test;
@@ -58,14 +58,14 @@ public void benchSetup() {
5858
typeRef = new TypeReference<TestObject>() {
5959
};
6060
JacksonAnnotationSupport.enable();
61-
ExtensionManager.registerTypeDecoder(TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
61+
JsoniterSpi.registerTypeDecoder(TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
6262
jackson = new ObjectMapper();
6363
jackson.registerModule(new AfterburnerModule());
6464
}
6565

6666
@Test
6767
public void test() throws IOException {
68-
ExtensionManager.registerExtension(new EmptyExtension() {
68+
JsoniterSpi.registerExtension(new EmptyExtension() {
6969
@Override
7070
public Type chooseImplementation(Type type) {
7171
if (ParameterizedTypeImpl.isSameClass(type, List.class)) {

demo/src/test/java/com/jsoniter/demo/SetterBinding.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.jsoniter.JsonIterator;
88
import com.jsoniter.ReflectionDecoderFactory;
99
import com.jsoniter.annotation.JacksonAnnotationSupport;
10-
import com.jsoniter.spi.ExtensionManager;
10+
import com.jsoniter.spi.JsoniterSpi;
1111
import com.jsoniter.spi.TypeLiteral;
1212
import org.junit.Test;
1313
import org.openjdk.jmh.Main;
@@ -67,15 +67,15 @@ public void benchSetup(BenchmarkParams params) {
6767
JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_STRICTLY);
6868
}
6969
if (params.getBenchmark().contains("withJsoniterReflection")) {
70-
ExtensionManager.registerTypeDecoder(ConstructorBinding.TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
70+
JsoniterSpi.registerTypeDecoder(ConstructorBinding.TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
7171
}
7272
}
7373
}
7474

7575
@Test
7676
public void test() throws IOException {
7777
benchSetup(null);
78-
ExtensionManager.registerTypeDecoder(ConstructorBinding.TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
78+
JsoniterSpi.registerTypeDecoder(ConstructorBinding.TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
7979
System.out.println(withJsoniter());
8080
System.out.println(withJackson());
8181
}

demo/src/test/java/com/jsoniter/demo/SimpleObjectBinding.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import com.jsoniter.DecodingMode;
1010
import com.jsoniter.JsonIterator;
1111
import com.jsoniter.ReflectionDecoderFactory;
12-
import com.jsoniter.spi.ExtensionManager;
12+
import com.jsoniter.spi.JsoniterSpi;
1313
import com.jsoniter.spi.TypeLiteral;
1414
import org.junit.Test;
1515
import org.openjdk.jmh.Main;
@@ -63,7 +63,7 @@ public void benchSetup(BenchmarkParams params) {
6363
testObject = new TestObject();
6464
if (params != null) {
6565
if (params.getBenchmark().contains("withReflection")) {
66-
ExtensionManager.registerTypeDecoder(TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
66+
JsoniterSpi.registerTypeDecoder(TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
6767
}
6868
if (params.getBenchmark().contains("withBindApiStrictMode")) {
6969
JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_STRICTLY);
@@ -77,7 +77,7 @@ public void benchSetup(BenchmarkParams params) {
7777
@Test
7878
public void test() throws IOException {
7979
benchSetup(null);
80-
ExtensionManager.registerTypeDecoder(TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
80+
JsoniterSpi.registerTypeDecoder(TestObject.class, ReflectionDecoderFactory.create(TestObject.class));
8181
System.out.println(withIterator());
8282
System.out.println(withIteratorIfElse());
8383
System.out.println(withIteratorIntern());

src/main/java/com/jsoniter/Codegen.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,27 @@ public static void setMode(DecodingMode mode) {
3030
}
3131

3232
static Decoder getDecoder(String cacheKey, Type type) {
33-
Decoder decoder = ExtensionManager.getDecoder(cacheKey);
33+
Decoder decoder = JsoniterSpi.getDecoder(cacheKey);
3434
if (decoder != null) {
3535
return decoder;
3636
}
3737
return gen(cacheKey, type);
3838
}
3939

4040
private synchronized static Decoder gen(String cacheKey, Type type) {
41-
Decoder decoder = ExtensionManager.getDecoder(cacheKey);
41+
Decoder decoder = JsoniterSpi.getDecoder(cacheKey);
4242
if (decoder != null) {
4343
return decoder;
4444
}
45-
List<Extension> extensions = ExtensionManager.getExtensions();
45+
List<Extension> extensions = JsoniterSpi.getExtensions();
4646
for (Extension extension : extensions) {
4747
type = extension.chooseImplementation(type);
4848
}
4949
type = chooseImpl(type);
5050
for (Extension extension : extensions) {
5151
decoder = extension.createDecoder(cacheKey, type);
5252
if (decoder != null) {
53-
ExtensionManager.addNewDecoder(cacheKey, decoder);
53+
JsoniterSpi.addNewDecoder(cacheKey, decoder);
5454
return decoder;
5555
}
5656
}
@@ -68,7 +68,7 @@ private synchronized static Decoder gen(String cacheKey, Type type) {
6868
}
6969
try {
7070
decoder = (Decoder) Class.forName(cacheKey).newInstance();
71-
ExtensionManager.addNewDecoder(cacheKey, decoder);
71+
JsoniterSpi.addNewDecoder(cacheKey, decoder);
7272
return decoder;
7373
} catch (Exception e) {
7474
if (mode == DecodingMode.STATIC_MODE) {
@@ -87,7 +87,7 @@ private synchronized static Decoder gen(String cacheKey, Type type) {
8787
staticGen(cacheKey, source);
8888
}
8989
decoder = dynamicGen(cacheKey, source);
90-
ExtensionManager.addNewDecoder(cacheKey, decoder);
90+
JsoniterSpi.addNewDecoder(cacheKey, decoder);
9191
return decoder;
9292
} catch (Exception e) {
9393
System.err.println("failed to generate decoder for: " + type + " with " + Arrays.toString(typeArgs));
@@ -106,7 +106,7 @@ private static Type chooseImpl(Type type) {
106106
} else {
107107
clazz = (Class) type;
108108
}
109-
Class implClazz = ExtensionManager.getTypeImplementation(clazz);
109+
Class implClazz = JsoniterSpi.getTypeImplementation(clazz);
110110
if (Collection.class.isAssignableFrom(clazz)) {
111111
Type compType = Object.class;
112112
if (typeArgs.length == 0) {
@@ -223,7 +223,7 @@ private static String genSource(String cacheKey, Class clazz, Type[] typeArgs) {
223223
if (Collection.class.isAssignableFrom(clazz)) {
224224
return CodegenImplArray.genCollection(clazz, typeArgs);
225225
}
226-
ClassDescriptor desc = ExtensionManager.getClassDescriptor(clazz, false);
226+
ClassDescriptor desc = JsoniterSpi.getClassDescriptor(clazz, false);
227227
if (shouldUseStrictMode(desc)) {
228228
return CodegenImplObject.genObjectUsingStrict(clazz, cacheKey, desc);
229229
} else {

src/main/java/com/jsoniter/CodegenAccess.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.jsoniter;
22

33
import com.jsoniter.spi.Decoder;
4-
import com.jsoniter.spi.ExtensionManager;
4+
import com.jsoniter.spi.JsoniterSpi;
55
import com.jsoniter.spi.TypeLiteral;
66

77
import java.io.IOException;
@@ -79,27 +79,27 @@ public static final <T> T read(JsonIterator iter, TypeLiteral<T> typeLiteral) th
7979
}
8080

8181
public static final boolean readBoolean(String cacheKey, JsonIterator iter) throws IOException {
82-
return ((Decoder.BooleanDecoder) ExtensionManager.getDecoder(cacheKey)).decodeBoolean(iter);
82+
return ((Decoder.BooleanDecoder) JsoniterSpi.getDecoder(cacheKey)).decodeBoolean(iter);
8383
}
8484

8585
public static final short readShort(String cacheKey, JsonIterator iter) throws IOException {
86-
return ((Decoder.ShortDecoder) ExtensionManager.getDecoder(cacheKey)).decodeShort(iter);
86+
return ((Decoder.ShortDecoder) JsoniterSpi.getDecoder(cacheKey)).decodeShort(iter);
8787
}
8888

8989
public static final int readInt(String cacheKey, JsonIterator iter) throws IOException {
90-
return ((Decoder.IntDecoder) ExtensionManager.getDecoder(cacheKey)).decodeInt(iter);
90+
return ((Decoder.IntDecoder) JsoniterSpi.getDecoder(cacheKey)).decodeInt(iter);
9191
}
9292

9393
public static final long readLong(String cacheKey, JsonIterator iter) throws IOException {
94-
return ((Decoder.LongDecoder) ExtensionManager.getDecoder(cacheKey)).decodeLong(iter);
94+
return ((Decoder.LongDecoder) JsoniterSpi.getDecoder(cacheKey)).decodeLong(iter);
9595
}
9696

9797
public static final float readFloat(String cacheKey, JsonIterator iter) throws IOException {
98-
return ((Decoder.FloatDecoder) ExtensionManager.getDecoder(cacheKey)).decodeFloat(iter);
98+
return ((Decoder.FloatDecoder) JsoniterSpi.getDecoder(cacheKey)).decodeFloat(iter);
9999
}
100100

101101
public static final double readDouble(String cacheKey, JsonIterator iter) throws IOException {
102-
return ((Decoder.DoubleDecoder) ExtensionManager.getDecoder(cacheKey)).decodeDouble(iter);
102+
return ((Decoder.DoubleDecoder) JsoniterSpi.getDecoder(cacheKey)).decodeDouble(iter);
103103
}
104104

105105
public static final <T> T read(String cacheKey, JsonIterator iter) throws IOException {

src/main/java/com/jsoniter/CodegenImplObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ private static boolean shouldReuseObject(Type valueType) {
508508
private static String genField(Binding field) {
509509
String fieldCacheKey = field.decoderCacheKey();
510510
// the field decoder might be registered directly
511-
Decoder decoder = ExtensionManager.getDecoder(fieldCacheKey);
511+
Decoder decoder = JsoniterSpi.getDecoder(fieldCacheKey);
512512
Type fieldType = field.valueType;
513513
if (decoder == null) {
514514
return String.format("(%s)%s", CodegenImplNative.getTypeName(fieldType), CodegenImplNative.genReadOp(fieldType));

src/main/java/com/jsoniter/ReflectionObjectDecoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public ReflectionObjectDecoder(Class clazz) {
3131
}
3232

3333
private final void init(Class clazz) throws Exception {
34-
ClassDescriptor desc = ExtensionManager.getClassDescriptor(clazz, true);
34+
ClassDescriptor desc = JsoniterSpi.getClassDescriptor(clazz, true);
3535
for (Binding param : desc.ctor.parameters) {
3636
addBinding(clazz, param);
3737
}
@@ -73,7 +73,7 @@ public Object decode(JsonIterator iter) throws IOException {
7373
}
7474
if (binding.decoder == null) {
7575
// the field decoder might be registered directly
76-
binding.decoder = ExtensionManager.getDecoder(binding.decoderCacheKey());
76+
binding.decoder = JsoniterSpi.getDecoder(binding.decoderCacheKey());
7777
}
7878
binding.idx = tempIdx;
7979
for (String fromName : binding.fromNames) {

src/main/java/com/jsoniter/annotation/JacksonAnnotationSupport.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package com.jsoniter.annotation;
22

33
import com.jsoniter.spi.Decoder;
4-
import com.jsoniter.spi.ExtensionManager;
4+
import com.jsoniter.spi.Encoder;
5+
import com.jsoniter.spi.JsoniterSpi;
56

67
import java.lang.annotation.Annotation;
78

89
public class JacksonAnnotationSupport extends JsoniterAnnotationSupport {
910

1011
public static void enable() {
11-
ExtensionManager.registerExtension(new JacksonAnnotationSupport());
12+
JsoniterSpi.registerExtension(new JacksonAnnotationSupport());
1213
}
1314

1415
@Override
@@ -57,6 +58,11 @@ public String[] from() {
5758
return new String[0];
5859
}
5960

61+
@Override
62+
public String[] to() {
63+
return new String[0];
64+
}
65+
6066
@Override
6167
public boolean required() {
6268
return jacksonObj.required();
@@ -72,6 +78,11 @@ public Class<?> implementation() {
7278
return Object.class;
7379
}
7480

81+
@Override
82+
public Class<? extends Encoder> encoder() {
83+
return Encoder.class;
84+
}
85+
7586
@Override
7687
public Class<? extends Annotation> annotationType() {
7788
return JsonProperty.class;

0 commit comments

Comments
 (0)