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: src/main/doc/manual.adoc
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,9 @@ User manual for Atbash JSON.
15
15
. SPI for defining JSON property name
16
16
. Integrated access-smart for additional features
17
17
18
+
Breaking changes
19
+
. Due to integration of _access-smart_, some internal classes are using now other dependent class names (to Atbash package names). But should not affect developer code which only uses @PublicAPI.
20
+
18
21
=== 0.9.0
19
22
20
23
. Initial release, based on the code of JSON smart v2.
@@ -162,6 +165,15 @@ public class PriceJSONWriter implements JSONWriter<PriceWithWriter> {
162
165
163
166
In this example, the Currency object implements the _JSONAware_ interface.
164
167
168
+
The last option discussed here, is to register the JSONWriter within the system, as follows
169
+
170
+
----
171
+
JSONValue.registerWriter(MyColor.class, new MyColorWriter());
172
+
----
173
+
174
+
Then the writer is picked up whenever you ask for converting the MyColor class in this example to JSON.
175
+
176
+
165
177
=== Custom reading of JSON
166
178
167
179
The conversion from JSON to an object instance can be customized by encoders which can be defined with _@MappedBy_.
@@ -185,6 +197,21 @@ An implementation of this interface or the class, needs a no argument constructo
185
197
186
198
Both classes needs to be specified by a @MappedBy annotation, _encoder()_ member for the simple CustomJSONEncoder implementation, _beanEncoder()_ member for CustomBeanJSONEncoder class.
187
199
200
+
Another customization is possible by registering encoders into the system itself, and then they don't need to be defined by a _mappedBy_ annotation. (It has more flexibility but is more difficult)
201
+
202
+
Start by extending the ++JSONEncoder<T>++ class and register it by
203
+
204
+
----
205
+
JSONValue.registerEncoder(<target>.class, new CustomEncoder());
206
+
207
+
JSONValue.registerEncoder(new TypeReference<MyType<...>>() {}, new CustomEncoder());
208
+
----
209
+
210
+
The second statement is for registering a Typed reference. This workaround is required to compensate for the Type erasure which is performed by Java.
211
+
212
+
After registering, this encoder are used when you ask to _parse_ a certain String to the specified type.
213
+
214
+
The test classes have examples if you want to use this type of customization.
0 commit comments