@@ -48,6 +48,66 @@ KRowMapper(::Dst) { colName: String ->
48
48
- Define the original deserializer ` annotation ` .
49
49
- Deserialize at initialization using the ` backing property ` .
50
50
51
+ #### Define a deserializer for the class
52
+ By assigning the ` KColumnDeserializer ` ` annotation ` to the ` constructor ` or ` factory method ` , deserialization by the ` KFunction ` can be performed.
53
+ The ` method ` that assigns this ` annotation ` must have one argument.
54
+
55
+ When the deserializer is defined in this way, the destination will be as follows.
56
+
57
+ ``` kotlin
58
+ data class Dst (
59
+ val foo : ByConstructor ,
60
+ val bar : BySecondaryConstructor ,
61
+ val baz : ByCompanionObject ,
62
+ val qux : ByStaticMethod
63
+ )
64
+ ```
65
+
66
+ ##### constructor
67
+ ``` kotlin
68
+ data class ByConstructor @KColumnDeserializer constructor(val fooString : String )
69
+ ```
70
+
71
+ ##### secondary constructor
72
+ ``` kotlin
73
+ data class BySecondaryConstructor (val barShort : Short ) {
74
+ @KColumnDeserializer
75
+ constructor (bar: String ) : this (bar.toShort())
76
+ }
77
+ ```
78
+
79
+ ##### factory method
80
+ ``` kotlin
81
+ data class ByCompanionObject (val bazInt : Int ) {
82
+ companion object {
83
+ @KColumnDeserializer
84
+ fun factory (baz : String ) = ByCompanionObject (baz.toInt())
85
+ }
86
+ }
87
+ ```
88
+
89
+ ##### (static method)
90
+ ` Java ` ` static method ` is also supported.
91
+
92
+ ``` java
93
+ public class ByStaticMethod {
94
+ private final String quxString;
95
+
96
+ public ByStaticMethod (String quxString ) {
97
+ this . quxString = quxString;
98
+ }
99
+
100
+ public String getQuxString () {
101
+ return quxString;
102
+ }
103
+
104
+ @KColumnDeserializer
105
+ public static ByStaticMethod factory (Integer quxArg ) {
106
+ return new ByStaticMethod (quxArg. toString());
107
+ }
108
+ }
109
+ ```
110
+
51
111
## Installation
52
112
Published on JitPack.
53
113
You can use this library on ` maven ` , ` gradle ` and any other build tools.
0 commit comments