forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestReflectionDecoder.java
More file actions
41 lines (32 loc) · 1.43 KB
/
TestReflectionDecoder.java
File metadata and controls
41 lines (32 loc) · 1.43 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
package com.jsoniter;
import com.jsoniter.spi.JsoniterSpi;
import junit.framework.TestCase;
import java.io.IOException;
public class TestReflectionDecoder extends TestCase {
public static class PackageLocal {
String field;
}
public void test_package_local() throws IOException {
JsoniterSpi.registerTypeDecoder(PackageLocal.class, ReflectionDecoderFactory.create(PackageLocal.class));
JsonIterator iter = JsonIterator.parse("{'field': 'hello'}".replace('\'', '"'));
PackageLocal obj = iter.read(PackageLocal.class);
assertEquals("hello", obj.field);
}
public static class Inherited extends PackageLocal {
}
public void test_inherited() throws IOException {
JsoniterSpi.registerTypeDecoder(Inherited.class, ReflectionDecoderFactory.create(Inherited.class));
JsonIterator iter = JsonIterator.parse("{'field': 'hello'}".replace('\'', '"'));
Inherited obj = iter.read(Inherited.class);
assertEquals("hello", obj.field);
}
public static class ObjectWithInt {
private int field;
}
public void test_int_field() throws IOException {
JsoniterSpi.registerTypeDecoder(ObjectWithInt.class, ReflectionDecoderFactory.create(ObjectWithInt.class));
JsonIterator iter = JsonIterator.parse("{'field': 100}".replace('\'', '"'));
ObjectWithInt obj = iter.read(ObjectWithInt.class);
assertEquals(100, obj.field);
}
}