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
Besides controlling how to decode a value, changing which JSON field bind to which object field is a very common requirement. Instead of only provide a `@JsonProperty` to change the mapping, jsoniter provide a much more powerful solution, a callback interface `Extension`. There are many things a extension can customize, here we focus on field renaming.
The callback `updateBinding` change the data source or decoder for a field. The `fromNames` is a `String[]`, with following options:
133
+
134
+
* null: do not customize this field
135
+
* empty array: disable this field binding. works like `@JsonIgnore`
136
+
* one or many: you can map multiple possible json field to one object field
137
+
138
+
The input is a concept called `Binding`, which not only represent field, but also constructor parameter and setter parameter. It contains the necessary information about what is binding, and you can customize how to bind it:
139
+
140
+
```
141
+
public class Binding {
142
+
// input
143
+
public Class clazz;
144
+
public String name;
145
+
public Type valueType;
146
+
public Annotation[] annotations;
147
+
// output
148
+
public String[] fromNames;
149
+
public Decoder decoder;
150
+
}
151
+
```
152
+
153
+
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.
0 commit comments