@@ -417,17 +417,41 @@ public static POJOSetter compilePOJOSetter(Method setterMethod, ClickHouseColumn
417417 false );
418418 } else if (!targetPrimitiveType .isPrimitive ()) {
419419 // boxing
420+ String sourceInternalClassName ;
421+ if (column .getDataType ().isSigned ()) {
422+ sourceInternalClassName = Type .getInternalName (sourceType );
423+ } else if (column .getDataType () == ClickHouseDataType .UInt64 ) {
424+ sourceInternalClassName = Type .getInternalName (BigInteger .class );
425+ } else if (column .getDataType () == ClickHouseDataType .Enum8 ) {
426+ sourceInternalClassName = Type .getInternalName (Byte .class );
427+ } else if (column .getDataType () == ClickHouseDataType .Enum16 ) {
428+ sourceInternalClassName = Type .getInternalName (Short .class );
429+ } else {
430+ sourceInternalClassName = Type .getInternalName (
431+ ClickHouseDataType .toObjectType (ClickHouseDataType .toWiderPrimitiveType (
432+ ClickHouseDataType .toPrimitiveType (sourceType ))));
433+ System .out .println ("sourceInternalClassName: " + sourceInternalClassName + " " + column .getColumnName ());
434+ }
420435 mv .visitVarInsn (ALOAD , 2 ); // load object
421- mv .visitMethodInsn (INVOKEVIRTUAL ,
422- Type .getInternalName (sourceType ),
423- targetPrimitiveType .getSimpleName () + "Value" ,
424- "()" + Type .getDescriptor (targetPrimitiveType ),
425- false );
426- mv .visitMethodInsn (INVOKESTATIC ,
427- Type .getInternalName (targetType ),
428- "valueOf" ,
429- "(" + Type .getDescriptor (targetPrimitiveType ) + ")" + Type .getDescriptor (targetType ),
430- false );
436+ mv .visitTypeInsn (CHECKCAST , sourceInternalClassName );
437+ try {
438+ if (!targetType .isAssignableFrom (Class .forName (sourceInternalClassName
439+ .replaceAll ("/" , "." )))) {
440+ mv .visitMethodInsn (INVOKEVIRTUAL ,
441+ sourceInternalClassName ,
442+ targetPrimitiveType .getSimpleName () + "Value" ,
443+ "()" + Type .getDescriptor (targetPrimitiveType ),
444+ false );
445+ mv .visitMethodInsn (INVOKESTATIC ,
446+ Type .getInternalName (targetType ),
447+ "valueOf" ,
448+ "(" + Type .getDescriptor (targetPrimitiveType ) + ")" + Type .getDescriptor (targetType ),
449+ false );
450+ }
451+ } catch (ClassNotFoundException e ) {
452+ throw new ClientException ("Cannot find class " + sourceInternalClassName + " to compile deserializer for "
453+ + column .getColumnName (), e );
454+ }
431455 } else {
432456 throw new ClientException ("Unsupported conversion from " + sourceType + " to " + targetType );
433457 }
0 commit comments