Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit b445316

Browse files
committed
KColumnDeserializerを用いるデシリアライザーに関する使い方を追記
1 parent 624f702 commit b445316

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,66 @@ KRowMapper(::Dst) { colName: String ->
4848
- Define the original deserializer `annotation`.
4949
- Deserialize at initialization using the `backing property`.
5050

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+
51111
## Installation
52112
Published on JitPack.
53113
You can use this library on `maven`, `gradle` and any other build tools.

0 commit comments

Comments
 (0)