You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: java-features.md
+7-9Lines changed: 7 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -156,9 +156,9 @@ All features is supported using the reflection mode, just slower, but still fast
156
156
157
157
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:
158
158
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
162
162
163
163
164
164
```java
@@ -168,6 +168,7 @@ public class DemoCodegenConfig implements CodegenConfig {
168
168
publicvoidsetup() {
169
169
// register custom decoder or extensions before codegen
170
170
// 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
@@ -224,14 +225,11 @@ then add code generation to maven build:
224
225
225
226
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.
226
227
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.
228
229
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
233
231
234
-
by setting the mode to static, dynamic code generation will not happen if the classto 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
0 commit comments