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

Commit a64292f

Browse files
committed
ファクトリーメソッドでのデシリアライズ関連を追記
1 parent 3603841 commit a64292f

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,41 @@ KRowMapper(::Dst) { colName: String ->
4444
### Deserialize column
4545
`KRowMapper` provides a deserialization function for the acquisition results of three patterns.
4646

47-
- Deserialize at initialization using the `backing property` or `factory method`.
47+
- Deserialize at initialization using the `factory method` or deserialize on initialize.
4848
- Define a deserializer for the `class`.
4949
- Define custom deserializer `annotation`.
5050

51+
#### Deserialize at initialization using the factory method or deserialize on initialize
52+
Deserialization within a `factory method` or initialization is the simplest method.
53+
Also, deserialization from multiple columns to one argument or from one column to multiple arguments cannot be realized other than this method.
54+
55+
```kotlin
56+
// example of deserialize on factory method
57+
data class Dst(
58+
foo: Foo,
59+
bar: Bar,
60+
baz: Baz?,
61+
...
62+
) {
63+
companion object {
64+
fun factory(
65+
foo: String,
66+
bar: String,
67+
baz: Int?,
68+
...
69+
): Dst {
70+
return Dst(
71+
Foo(foo),
72+
Bar.fromString(bar),
73+
baz?.let { Baz(it) },
74+
...
75+
)
76+
}
77+
}
78+
}
79+
80+
val dst: Dst = jdbcTemplate.query(query, KRowMapper((Dst)::factory))
81+
```
5182

5283
#### Define a deserializer for the class
5384
By assigning the `KColumnDeserializer` `annotation` to the `constructor` or `factory method`, deserialization by the `KFunction` can be performed.

0 commit comments

Comments
 (0)