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 ->
44
44
### Deserialize column
45
45
` KRowMapper ` provides a deserialization function for the acquisition results of three patterns.
46
46
47
- - Deserialize at initialization using the ` backing property ` or ` factory method ` .
47
+ - Deserialize at initialization using the ` factory method ` or deserialize on initialize .
48
48
- Define a deserializer for the ` class ` .
49
49
- Define custom deserializer ` annotation ` .
50
50
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
+ ```
51
82
52
83
#### Define a deserializer for the class
53
84
By 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