确认
当前程序版本
3.4.1
问题描述
自定义TypeHandler
@MappedTypes({Object.class})
@MappedJdbcTypes(JdbcType.VARCHAR)
public class JsonTypeHandler
private final Class<T> type;
public JsonTypeHandler(Class<T> type) {
this.type = type;
}
@Override
protected T parse(String json) {
return JsonUtils.toObject(json, type);
}
@Override
protected String toJson(T obj) {
return JsonUtils.toJsonString(obj);
}
}
表实体类
@TableName(value = "user",autoResultMap = true) class User{ @TableField(value = "extend",typeHandler = JsonTypeHandler.class) private Extend extend; }
执行以下代码
Extend extend = new Extend() ... lambdaUpdate().set(User::getExtend, extend).eq(User::getId,id).update();
目前发现以上lambda进行update报以下错误,同时debug发现报错 Cause: java.sql.SQLException: Incorrect string value: '\xAC\xED\x00\x05sr...' for column 'task_output' at row 1 at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199) at jdk.internal.reflect.GeneratedMethodAccessor527.invoke(Unknown Source)
使用非lambda方式可以成功update。
希望能详细说明自定义TypeHandler在哪些情况下无法生效
详细堆栈日志
Cause: java.sql.SQLException: Incorrect string value: '\xAC\xED\x00\x05sr...' for column 'task_output' at row 1
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)
at jdk.internal.reflect.GeneratedMethodAccessor527.invoke(Unknown Source)
Comment From: miemieYaho
搜issues
Comment From: john1337
现在这个实现方式好鸡肋