@@ -109,6 +109,11 @@ fun schema(kType: KType): DataType = kotlinEncoderFor<Any?>(kType).schema()
109
109
110
110
object KotlinTypeInference {
111
111
112
+ // TODO this hack is a WIP and can give errors
113
+ // TODO it's to make data classes get column names like "age" with functions like "getAge"
114
+ // TODO instead of column names like "getAge"
115
+ var DO_NAME_HACK = false
116
+
112
117
/* *
113
118
* @param kClass the class for which to infer the encoder.
114
119
* @param arguments the generic type arguments for the class.
@@ -255,22 +260,22 @@ object KotlinTypeInference {
255
260
currentType == typeOf< scala.Double > () -> AgnosticEncoders .`PrimitiveDoubleEncoder $`.`MODULE $`
256
261
257
262
// boxed primitives java / kotlin
258
- currentType == typeOf <Boolean ?>() -> AgnosticEncoders .`BoxedBooleanEncoder $`.`MODULE $`
259
- currentType == typeOf <Byte ?>() -> AgnosticEncoders .`BoxedByteEncoder $`.`MODULE $`
260
- currentType == typeOf <Short ?>() -> AgnosticEncoders .`BoxedShortEncoder $`.`MODULE $`
261
- currentType == typeOf <Int ?>() -> AgnosticEncoders .`BoxedIntEncoder $`.`MODULE $`
262
- currentType == typeOf <Long ?>() -> AgnosticEncoders .`BoxedLongEncoder $`.`MODULE $`
263
- currentType == typeOf <Float ?>() -> AgnosticEncoders .`BoxedFloatEncoder $`.`MODULE $`
264
- currentType == typeOf <Double ?>() -> AgnosticEncoders .`BoxedDoubleEncoder $`.`MODULE $`
263
+ currentType.isSubtypeOf <Boolean ?>() -> AgnosticEncoders .`BoxedBooleanEncoder $`.`MODULE $`
264
+ currentType.isSubtypeOf <Byte ?>() -> AgnosticEncoders .`BoxedByteEncoder $`.`MODULE $`
265
+ currentType.isSubtypeOf <Short ?>() -> AgnosticEncoders .`BoxedShortEncoder $`.`MODULE $`
266
+ currentType.isSubtypeOf <Int ?>() -> AgnosticEncoders .`BoxedIntEncoder $`.`MODULE $`
267
+ currentType.isSubtypeOf <Long ?>() -> AgnosticEncoders .`BoxedLongEncoder $`.`MODULE $`
268
+ currentType.isSubtypeOf <Float ?>() -> AgnosticEncoders .`BoxedFloatEncoder $`.`MODULE $`
269
+ currentType.isSubtypeOf <Double ?>() -> AgnosticEncoders .`BoxedDoubleEncoder $`.`MODULE $`
265
270
266
271
// boxed primitives scala
267
- currentType == typeOf < scala.Boolean? > () -> AgnosticEncoders .`BoxedBooleanEncoder $`.`MODULE $`
268
- currentType == typeOf < scala.Byte? > () -> AgnosticEncoders .`BoxedByteEncoder $`.`MODULE $`
269
- currentType == typeOf < scala.Short? > () -> AgnosticEncoders .`BoxedShortEncoder $`.`MODULE $`
270
- currentType == typeOf < scala.Int? > () -> AgnosticEncoders .`BoxedIntEncoder $`.`MODULE $`
271
- currentType == typeOf < scala.Long? > () -> AgnosticEncoders .`BoxedLongEncoder $`.`MODULE $`
272
- currentType == typeOf < scala.Float? > () -> AgnosticEncoders .`BoxedFloatEncoder $`.`MODULE $`
273
- currentType == typeOf < scala.Double? > () -> AgnosticEncoders .`BoxedDoubleEncoder $`.`MODULE $`
272
+ currentType.isSubtypeOf < scala.Boolean? > () -> AgnosticEncoders .`BoxedBooleanEncoder $`.`MODULE $`
273
+ currentType.isSubtypeOf < scala.Byte? > () -> AgnosticEncoders .`BoxedByteEncoder $`.`MODULE $`
274
+ currentType.isSubtypeOf < scala.Short? > () -> AgnosticEncoders .`BoxedShortEncoder $`.`MODULE $`
275
+ currentType.isSubtypeOf < scala.Int? > () -> AgnosticEncoders .`BoxedIntEncoder $`.`MODULE $`
276
+ currentType.isSubtypeOf < scala.Long? > () -> AgnosticEncoders .`BoxedLongEncoder $`.`MODULE $`
277
+ currentType.isSubtypeOf < scala.Float? > () -> AgnosticEncoders .`BoxedFloatEncoder $`.`MODULE $`
278
+ currentType.isSubtypeOf < scala.Double? > () -> AgnosticEncoders .`BoxedDoubleEncoder $`.`MODULE $`
274
279
275
280
// leaf encoders
276
281
currentType.isSubtypeOf<String ?>() -> AgnosticEncoders .`StringEncoder $`.`MODULE $`
@@ -482,7 +487,8 @@ object KotlinTypeInference {
482
487
val writeMethodName = (prop as ? KMutableProperty <* >)?.setter?.javaMethod?.name
483
488
484
489
DirtyProductEncoderField (
485
- name = paramName,
490
+ doNameHack = DO_NAME_HACK ,
491
+ columnName = paramName,
486
492
readMethodName = readMethodName,
487
493
writeMethodName = writeMethodName,
488
494
encoder = encoder,
@@ -535,9 +541,10 @@ object KotlinTypeInference {
535
541
}
536
542
537
543
internal open class DirtyProductEncoderField (
538
- private val name : String , // the name used for the column
544
+ private val columnName : String , // the name used for the column
539
545
private val readMethodName : String , // the name of the method used to read the value
540
546
private val writeMethodName : String? ,
547
+ private val doNameHack : Boolean ,
541
548
encoder : AgnosticEncoder <* >,
542
549
nullable : Boolean ,
543
550
metadata : Metadata = Metadata .empty(),
@@ -554,12 +561,15 @@ internal open class DirtyProductEncoderField(
554
561
555
562
/* *
556
563
* This dirty trick only works because in [SerializerBuildHelper], [ProductEncoder]
557
- * creates an [Invoke] using [name ] first and then calls [name ] again to retrieve
564
+ * creates an [Invoke] using [columnName ] first and then calls [columnName ] again to retrieve
558
565
* the name of the column. This way, we can alternate between the two names.
559
566
*/
560
567
override fun name (): String =
561
- if (i++ % 2 == 0 ) readMethodName
562
- else name
568
+ when (doNameHack) {
569
+ true -> if (i++ % 2 == 0 ) readMethodName else columnName
570
+ false -> readMethodName
571
+ }
572
+
563
573
564
574
override fun canEqual (that : Any? ): Boolean = that is AgnosticEncoders .EncoderField
565
575
0 commit comments