Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 66c1993

Browse files
authoredDec 17, 2016
Update java-extension.md
1 parent 0539fc4 commit 66c1993

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 

‎java-extension.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,21 @@ public interface Decoder {
2626
Object decode(JsonIterator iter) throws IOException;
2727
}
2828
```
29+
30+
The unique extensiblity of jsoniter is coming from the iterator-api. The simplest form of bind-api callback is `Decoder`, which takes the current `iterator` instance pointing to the next value to read, and read the object for the binding. For example
31+
32+
```java
33+
JsonIterator.registerTypeDecoder(Date.class, new Decoder() {
34+
@Override
35+
public Object decode(final JsonIterator iter) throws IOException {
36+
return new Date(iter.readLong());
37+
}
38+
});
39+
```
40+
41+
when a `Date` class to read, the registered decoder will be called.
42+
43+
```java
44+
JsonIterator iter = JsonIterator.parse("1481365190000");
45+
iter.read(Date.class); // Sat Dec 10 18:19:50 CST 2016
46+
```

0 commit comments

Comments
 (0)
Please sign in to comment.