forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSpiPropertyDecoder.java
More file actions
45 lines (38 loc) · 1.41 KB
/
TestSpiPropertyDecoder.java
File metadata and controls
45 lines (38 loc) · 1.41 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
package com.jsoniter;
import com.jsoniter.spi.Decoder;
import com.jsoniter.spi.JsoniterSpi;
import com.jsoniter.spi.TypeLiteral;
import junit.framework.TestCase;
import java.io.IOException;
public class TestSpiPropertyDecoder extends TestCase {
static {
// JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH);
}
public static class TestObject1<A> {
public String field;
}
public void test_PropertyDecoder() {
JsoniterSpi.registerPropertyDecoder(TestObject1.class, "field", new Decoder() {
@Override
public Object decode(JsonIterator iter) throws IOException {
iter.skip();
return "hello";
}
});
TestObject1 obj = JsonIterator.deserialize("{\"field\":100}", TestObject1.class);
assertEquals("hello", obj.field);
}
public void test_PropertyDecoder_for_type_literal() {
TypeLiteral<TestObject1<Object>> typeLiteral = new TypeLiteral<TestObject1<Object>>() {
};
JsoniterSpi.registerPropertyDecoder(typeLiteral, "field", new Decoder() {
@Override
public Object decode(JsonIterator iter) throws IOException {
iter.skip();
return "world";
}
});
TestObject1 obj = JsonIterator.deserialize("{\"field\":100}", typeLiteral);
assertEquals("world", obj.field);
}
}