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-extension.md
+96Lines changed: 96 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -261,4 +261,100 @@ public static class StaticFactory {
261
261
262
262
To enable jsoniter annotation support `JsoniterAnnotationSupport.enable()` must be called first
263
263
264
+
# Setter support
264
265
266
+
The binding is done in this sequence
267
+
268
+
```
269
+
1. create instance using constructor
270
+
2. bind fields
271
+
3. call setters
272
+
```
273
+
274
+
By default, methods like `setName(val)` will be caleld with field value from `name`. You can choose to use other kinds of methods as setters. For example
275
+
276
+
```
277
+
public static class WithSetter {
278
+
279
+
private int field1;
280
+
private int field2;
281
+
282
+
@JsonSetter
283
+
public void initialize(@JsonProperty("field1") int field1, @JsonProperty("field2") int field2) {
284
+
this.field1 = field1;
285
+
this.field2 = field2;
286
+
}
287
+
}
288
+
```
289
+
290
+
This annotation support is implemented by `Extension` as well. The callback is:
291
+
292
+
```
293
+
public interface Extension {
294
+
// ...
295
+
List<CustomizedSetter> getSetters(Class clazz);
296
+
// ...
297
+
}
298
+
299
+
public class CustomizedSetter {
300
+
/**
301
+
* which method to call to set value
302
+
*/
303
+
public String methodName;
304
+
305
+
/**
306
+
* the parameters to bind
307
+
*/
308
+
public List<Binding> parameters = new ArrayList<Binding>();
309
+
}
310
+
```
311
+
312
+
The setter parameters, constructor parameters and fields are all just bindings. Those bindings can be updated by extension, to change data source and decoder.
313
+
314
+
# Full extension interface
315
+
316
+
```
317
+
public interface Extension {
318
+
/**
319
+
* Customize type decoding
320
+
*
321
+
* @param type change how to decode the type
322
+
* @param typeArgs for generic type, there might be arguments
323
+
* @return null, if no special customization needed
0 commit comments