This repository was archived by the owner on Jan 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -228,6 +228,46 @@ To deal with this problem, `KRowMapper` provides the following three types of de
228
228
2 . Deserialization by creating your own custom deserialization annotations.
229
229
3 . Deserialization from multiple arguments.
230
230
231
+ #### Deserialization by using the KColumnDeserializer annotation
232
+ If it is a self-made class and can be initialized from a single argument, deserialization using the ` KColumnDeserializer ` annotation can be used.
233
+ ` KColumnDeserializer ` annotation can be used to ` constructor ` or ` factory method ` defined in ` companion object ` .
234
+
235
+ ``` kotlin
236
+ // for primary constructor
237
+ data class FooId @KColumnDeserializer constructor(val id : Int )
238
+ ```
239
+
240
+ ``` kotlin
241
+ // for secondary constructor
242
+ data class FooId (val id : Int ) {
243
+ @KColumnDeserializer
244
+ constructor (id: String ) : this (id.toInt())
245
+ }
246
+ ```
247
+
248
+ ``` kotlin
249
+ // for factory method
250
+ data class FooId (val id : Int ) {
251
+ companion object {
252
+ @KColumnDeserializer
253
+ fun of (id : String ): FooId = FooId (id.toInt())
254
+ }
255
+ }
256
+ ```
257
+
258
+ Class with ` KColumnDeserializer ` annotation can be mapped as an argument without any special description.
259
+
260
+ ``` kotlin
261
+ data class Dst (
262
+ fooId : FooId ,
263
+ bar : String ,
264
+ baz : Int? ,
265
+
266
+ ...
267
+
268
+ )
269
+ ```
270
+
231
271
### Use default arguments
232
272
` KRowMapper ` supports ` default arguments ` .
233
273
` Default arguments ` are available in the following situations:
You can’t perform that action at this time.
0 commit comments