You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 20, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+6-177Lines changed: 6 additions & 177 deletions
Original file line number
Diff line number
Diff line change
@@ -220,184 +220,13 @@ val mapper: KRowMapper<Dst> = KRowMapper(::Dst, parameterNameConverter)
220
220
By using the contents described so far, you can perform more flexible and safe mapping compared to `BeanPropertyRowMapper`.
221
221
In addition, by making full use of the abundant functions provided by `KRowMapper`, further labor saving is possible.
222
222
223
-
### Deserialize column
224
-
`KRowMapper` provides a deserialization function for the acquisition results of three patterns.
223
+
### Deserialization
224
+
Since `KRowMapper` gets the value from `java.sql.ResultSet`, by default it is not possible to get the type which is not supported by this implementation.
225
+
To deal with this problem, `KRowMapper` provides the following three types of deserialization methods in addition to the default conversion function.
225
226
226
-
- Deserialize at initialization using the `factory method` or deserialize on initialize.
227
-
- Define a deserializer for the `class`.
228
-
- Define custom deserializer `annotation`.
229
-
230
-
#### Deserialize at initialization using the factory method or deserialize on initialize
231
-
Deserialization within a `factory method` or initialization is the simplest method.
232
-
Also, deserialization from multiple columns to one argument or from one column to multiple arguments cannot be realized other than this method.
233
-
234
-
```kotlin
235
-
// example of deserialize on factory method
236
-
data classDst(
237
-
foo:Foo,
238
-
bar:Bar,
239
-
baz:Baz?,
240
-
...
241
-
) {
242
-
companionobject {
243
-
funfactory(
244
-
foo:String,
245
-
bar:String,
246
-
baz:Int?,
247
-
...
248
-
): Dst {
249
-
returnDst(
250
-
Foo(foo),
251
-
Bar.fromString(bar),
252
-
baz?.let { Baz(it) },
253
-
...
254
-
)
255
-
}
256
-
}
257
-
}
258
-
259
-
val dst:Dst= jdbcTemplate.query(query, KRowMapper((Dst)::factory))
260
-
```
261
-
262
-
#### Define a deserializer for the class
263
-
By assigning the `KColumnDeserializer``annotation` to the `constructor` or `factory method`, deserialization by the `KFunction` can be performed.
264
-
The `method` that assigns this `annotation` must have one argument.
265
-
266
-
When the deserializer is defined in this way, the destination will be as follows.
267
-
268
-
```kotlin
269
-
data classDst(
270
-
valfoo:ByConstructor,
271
-
valbar:BySecondaryConstructor,
272
-
valbaz:ByCompanionObject,
273
-
valqux:ByStaticMethod
274
-
)
275
-
```
276
-
277
-
##### constructor
278
-
```kotlin
279
-
data classByConstructor @KColumnDeserializer constructor(valfooString:String)
280
-
```
281
-
282
-
##### secondary constructor
283
-
```kotlin
284
-
data classBySecondaryConstructor(valbarShort:Short) {
0 commit comments