I am using a DTO which contains Set<UUID>
and Set<String>
.
public class MyBatisDTO implements Serializable{
// other attributes
private Set<UUID> uuidSet;
private Set<String> stringSet;
.....
}
A typeHandler has already been registered for Generic-Type Set<T>
.
@MappedJdbcTypes(JdbcType.OTHER)
@MappedTypes(Set.class)
public class SetTypeHandler extends BaseTypeHandler<Set<T>> {
@Override
public Set<T> getNullableResult(ResultSet rs, String columnName) throws SQLException {
return mapFromJson(rs.getString(columnName));
}
.......
Now the problem is that when above mentioned MyBatisDTO.java is being mapped from DB values where both columns uuidSet
and stringset
are stored as jsonb
values, typeHandler picks the Generic type as String -> T extends String
for Set<UUID> uuidSet;
as well which is leading to auto-type conversion to all items of uuidSet
as String. This is not an error but in debugging it can be seen that uuidSet
contains String
values.
Later on, which also leads in de-serialization of JAX-RS response but thats another topic which is not important at the moment.
My question is Is there a way that we can enforce a typeHandler on property's level? so I am looking for a solution in which I may attach custom TypeHandler on property level, something like this
//SUDO_CODE
public class MyBatisDTO implements Serializable{
// other attributes
@TypeHandler ("com.mybatis.handlers.typeHandler.SetUUIDTypeHandler")
private Set<UUID> uuidSet;
@TypeHandler ("com.mybatis.handlers.typeHandler.SetStringTypeHandler")
private Set<String> stringSet;
.....
}
OR if there is a way to mention these typeHandlers on Mapper-Level, something like this?
@Mapper
public interface MyBatisMapper {
//TYPE HANDLER ATTACHMENT/CONFIGURATION HERE ..???
@Select("SELECT uuidSet, stringSet FROM MyBatisDTO WHERE param = #{param}")
Cursor<MyBatisDTO> getData(@Param("param") final UUID param);
.....
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…