Skip to content

Commit 76b754a

Browse files
authored
Update java-features.md
1 parent acf78c2 commit 76b754a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

java-features.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ All features is supported using the reflection mode, just slower, but still fast
156156

157157
When you want to have maximum performance, and the platform you use can not support dynamic code generation, then you can try static codegen. To enable static codegen, 3 things need to be done:
158158

159-
* define what class need to be decoded or encoded
160-
* add code generation to maven build process
161-
* switch mode to static codegen when decoding or encoding
159+
* define what class need to be decoded or encoded using CodegenConfig
160+
* add code generation to maven/gradle build process
161+
* call CodegenConfig setup before use encoder or decoder
162162

163163

164164
```java
@@ -168,6 +168,7 @@ public class DemoCodegenConfig implements CodegenConfig {
168168
public void setup() {
169169
// register custom decoder or extensions before codegen
170170
// so that we doing codegen, we know in which case, we need to callback
171+
JsonIterator.setMode(DecodingMode.STATIC_MODE); // must set to static mode
171172
JsoniterSpi.registerFieldDecoder(User.class, "score", new Decoder.IntDecoder() {
172173
@Override
173174
public int decodeInt(JsonIterator iter) throws IOException {
@@ -224,14 +225,11 @@ then add code generation to maven build:
224225

225226
the generated java source code will be written out to `src/main/java` folder of your project. The output dir is specified by setting the workingDirectory to the `project.build.sourceDirectory`. The output dir can also be specified as the second argument to StaticCodeGenerator.
226227

227-
The final step is to switch mode
228+
by setting the mode to static, dynamic code generation will not happen if the class to decode/encode does not have corresponding decoder/encoder, instead exception will be thrown.
228229

229-
```java
230-
JsonIterator.setMode(DecodingMode.STATIC_MODE); // set mode before using
231-
JsonIterator.deserialize(...
232-
```
230+
For normal java project, please refer to demo: https://github.com/json-iterator/java/tree/master/demo
233231

234-
by setting the mode to static, dynamic code generation will not happen if the class to decode/encode does not have corresponding decoder/encoder, instead exception will be thrown.
232+
For android project, please refer to the android demo: https://github.com/json-iterator/java/tree/master/android-demo
235233

236234
# Object binding styles
237235

0 commit comments

Comments
 (0)