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 +32
-1
lines changed Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff 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
5384By assigning the ` KColumnDeserializer ` ` annotation ` to the ` constructor ` or ` factory method ` , deserialization by the ` KFunction ` can be performed.
You can’t perform that action at this time.
0 commit comments