DefaultDataTypeResolver implements DataTypeResolver { @Override public DataType resolve(EntityPropertyDescriptor descriptor) { return descriptor.findAnnotation(ColumnType.class) .map(type -> { RDBColumnMetadata column = descriptor.getColumn(); Class<?> javaType = type.javaType() == Void.class ? descriptor.getPropertyType() : type.javaType(); if (!type.typeId().isEmpty()) { return column == null ? DataType.custom(type.typeId(), type.name(), type.jdbcType(), javaType) : column.getDialect().convertDataType(type.typeId()); } else if (type.type() != DataType.class) { return getDataTypeInstance(type.type()); } else { if (type.javaType() == Void.class && null != column) { return column.getDialect() .convertDataType(type.jdbcType().getName()); } return DataType.jdbc(type.jdbcType(), javaType); } }).orElse(null); }  @Override DataType resolve(EntityPropertyDescriptor descriptor); static final DefaultDataTypeResolver INSTANCE; }
@Test @SneakyThrows public void test() { DefaultDataTypeResolver resolver = new DefaultDataTypeResolver(); Map<String, PropertyDescriptor> descriptorMap = Stream.of(PropertyUtils.getPropertyDescriptors(Entity.class)) .collect(Collectors.toMap(PropertyDescriptor::getName, Function.identity())); { PropertyDescriptor name = descriptorMap.get("name"); DataType dataType = resolver.resolve(SimpleEntityPropertyDescriptor.of(name,null)); assertNotNull(dataType); Assert.assertEquals(dataType.getId(), "varchar"); Assert.assertEquals(dataType.getSqlType(), JDBCType.VARCHAR); Assert.assertEquals(dataType.getJavaType(), String.class); } { PropertyDescriptor property = descriptorMap.get("jsonArray"); DataType dataType = resolver.resolve(SimpleEntityPropertyDescriptor.of(property,null)); assertNotNull(dataType); Assert.assertEquals(dataType.getId(), "jsonb"); Assert.assertEquals(dataType.getSqlType(), JDBCType.VARCHAR); Assert.assertEquals(dataType.getJavaType(), String.class); } { PropertyDescriptor property = descriptorMap.get("custom"); DataType dataType = resolver.resolve(SimpleEntityPropertyDescriptor.of(property,null)); assertNotNull(dataType); Assert.assertEquals(dataType.getId(), "custom"); Assert.assertEquals(dataType.getSqlType(), JDBCType.CLOB); Assert.assertEquals(dataType.getJavaType(), String.class); } { PropertyDescriptor property = descriptorMap.get("id"); DataType dataType = resolver.resolve(SimpleEntityPropertyDescriptor.of(property,null)); assertNotNull(dataType); Assert.assertEquals(dataType.getId(), "varchar"); Assert.assertEquals(dataType.getSqlType(), JDBCType.VARCHAR); Assert.assertEquals(dataType.getJavaType(), String.class); } }