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
The callback `updateBinding` change the data source or decoder for a field. The `fromNames` is a `String[]`, with following options:
135
+
The callback `updateClassDescriptor` change the data source or decoder for a field. The `fromNames` is a `String[]`, with following options:
133
136
134
137
* null: do not customize this field
135
138
* empty array: disable this field binding. works like `@JsonIgnore`
@@ -143,18 +146,26 @@ public class Binding {
143
146
publicClass clazz;
144
147
publicString name;
145
148
publicType valueType;
149
+
publicTypeLiteral valueTypeLiteral;
146
150
publicAnnotation[] annotations;
147
151
// output
148
-
publicString[] fromNames;
152
+
publicString[] fromNames; // for decoder
153
+
publicString[] toNames; // for encoder
149
154
publicDecoder decoder;
155
+
publicEncoder encoder;
156
+
publicboolean failOnMissing;
157
+
publicboolean failOnPresent;
158
+
// optional
159
+
publicField field;
160
+
publicint idx;
150
161
}
151
162
```
152
163
153
164
So we can also customize the field decoder using `Extension` to update bindings. Actually type decoder and field decoder callback is just a shortcut. The `Extension` interface can do all the job.
154
165
155
166
# Your own annotation support
156
167
157
-
It is very common to support `@JsonProperty` to rename field. By registering your own extension, you can implement them very easily.
168
+
It is very common to support `@JsonProperty` to rename field. Jsoniter also comes with built-in support for annotation. But by registering your own extension, you can implement them very easily.
@@ -205,25 +216,21 @@ If you do not want to write annotation support yourself, you can use built-in `c
205
216
Jsoniter can work with class without default constructor. The extension can customize the constructor to be used for specific class. The constructor can also be a static method, instead of real constructor.
206
217
207
218
```java
208
-
publicinterfaceExtension {
209
-
// ...
210
-
CustomizedConstructorgetConstructor(Classclazz);
211
-
/// ...
212
-
}
213
-
214
-
publicclassCustomizedConstructor {
219
+
publicclassConstructorDescriptor {
215
220
/**
216
221
* set to null if use constructor
217
222
* otherwise use static method
218
223
*/
219
224
publicString staticMethodName;
225
+
// optional
226
+
publicConstructor ctor;
227
+
// optional
228
+
publicMethod staticFactory;
220
229
221
230
/**
222
231
* the parameters to call constructor or static method
@@ -318,35 +322,18 @@ public interface Extension {
318
322
/**
319
323
* Customize type decoding
320
324
*
325
+
* @param cacheKey
321
326
* @param type change how to decode the type
322
-
* @param typeArgs for generic type, there might be arguments
323
327
* @return null, if no special customization needed
324
328
*/
325
-
DecodercreateDecoder(Typetype, Type... typeArgs);
326
-
327
-
/**
328
-
* Customize the binding source or decoder
329
-
*
330
-
* @param field binding information
331
-
* @return true, if stops other extension from customizing same field
332
-
*/
333
-
booleanupdateBinding(Bindingfield);
334
-
335
-
/**
336
-
* Customize which constructor to call
337
-
*
338
-
* @param clazz the class of instance to create
339
-
* @return null, if fallback to default behavior
340
-
*/
341
-
CustomizedConstructorgetConstructor(Classclazz);
329
+
DecodercreateDecoder(StringcacheKey, Typetype);
342
330
343
331
/**
344
-
* Customize setters to call after instance is created and fields set
332
+
* Update binding is done for the class
345
333
*
346
-
* @param clazz the class that is binding
347
-
* @return null, if fallback to default behavior
334
+
* @param desc binding information
348
335
*/
349
-
List<CustomizedSetter>getSetters(Classclazz);
336
+
voidupdateClassDescriptor(ClassDescriptordesc);
350
337
}
351
338
```
352
339
@@ -362,7 +349,7 @@ Also the decoder interface is powered with iterator-api to iterate on the lowest
362
349
There is a feature flag of jackson called `ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT`. The intention is to decode input like `[]` as null, as PHP might treat empty object as empty array. To support this feature, we can register a extension
0 commit comments