-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Description
MyBatis version
3.4.5
For example:
TypeHandlerRegistry tr = ...
tr.register(Address.class, TypeHandlers.jsonPOJO(Address.class));
tr.hasTypeHandler(Address.class); // which return truebut
TypeHandlerRegistry tr = ...
tr.hasTypeHandler(Address.class);
tr.register(Address.class, TypeHandlers.jsonPOJO(Address.class));
tr.hasTypeHandler(Address.class); // which return falseWhere the question is coming.
In org.apache.ibatis.type.TypeHandlerRegistry, NULL_TYPE_HANDLER_MAP is used for representing no handler at all.
private Map<JdbcType, TypeHandler<?>> getJdbcHandlerMap(Type type) {
TYPE_HANDLER_MAP.put(type, jdbcHandlerMap == null ?
NULL_TYPE_HANDLER_MAP : jdbcHandlerMap);
return jdbcHandlerMap;
}And with the following code:
private void register(Type javaType, JdbcType jdbcType, TypeHandler<?> handler) {
if (javaType != null) {
Map<JdbcType, TypeHandler<?>> map = TYPE_HANDLER_MAP.get(javaType);
// here
if (map == null) {
map = new HashMap<JdbcType, TypeHandler<?>>();
TYPE_HANDLER_MAP.put(javaType, map);
}
map.put(jdbcType, handler);
}
ALL_TYPE_HANDLERS_MAP.put(handler.getClass(), handler);
}The code if (map == null) uses null represent an empty map instead of using NULL_TYPE_HANDLER_MAP along with, which will make all handlers cannot be registered.