diff --git a/src/main/java/org/apache/ibatis/type/TypeHandlerRegistry.java b/src/main/java/org/apache/ibatis/type/TypeHandlerRegistry.java index 9919a889d90..77addabcf2c 100644 --- a/src/main/java/org/apache/ibatis/type/TypeHandlerRegistry.java +++ b/src/main/java/org/apache/ibatis/type/TypeHandlerRegistry.java @@ -241,11 +241,12 @@ private Map> getJdbcHandlerMap(Type type) { } if (jdbcHandlerMap == null && type instanceof Class) { Class clazz = (Class) type; - if (clazz.isEnum()) { - jdbcHandlerMap = getJdbcHandlerMapForEnumInterfaces(clazz, clazz); + if (Enum.class.isAssignableFrom(clazz)) { + Class enumClass = clazz.isAnonymousClass() ? clazz.getSuperclass() : clazz; + jdbcHandlerMap = getJdbcHandlerMapForEnumInterfaces(enumClass, enumClass); if (jdbcHandlerMap == null) { - register(clazz, getInstance(clazz, defaultEnumTypeHandler)); - return typeHandlerMap.get(clazz); + register(enumClass, getInstance(enumClass, defaultEnumTypeHandler)); + return typeHandlerMap.get(enumClass); } } else { jdbcHandlerMap = getJdbcHandlerMapForSuperclass(clazz); diff --git a/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/EnumInterfaceTypeHandlerTest.java b/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/EnumInterfaceTypeHandlerTest.java index 08aeca91671..50d8e218ab7 100644 --- a/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/EnumInterfaceTypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/EnumInterfaceTypeHandlerTest.java @@ -65,4 +65,18 @@ void shouldInsertAUser() { assertEquals(Color.BLUE, result.getColor()); } } + + @Test + void shouldInsertAUserWithoutParameterTypeInXmlElement() { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { + XmlMapper mapper = sqlSession.getMapper(XmlMapper.class); + User user = new User(); + user.setId(2); + user.setColor(Color.BLUE); + mapper.insertUser(user); + User result = sqlSession.getMapper(Mapper.class).getUser(2); + assertEquals(Color.BLUE, result.getColor()); + } + } + } diff --git a/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/XmlMapper.java b/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/XmlMapper.java new file mode 100644 index 00000000000..6e58776591b --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/XmlMapper.java @@ -0,0 +1,20 @@ +/** + * Copyright 2009-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ibatis.submitted.enum_interface_type_handler; + +public interface XmlMapper { + int insertUser(User user); +} diff --git a/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/XmlMapper.xml b/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/XmlMapper.xml new file mode 100644 index 00000000000..367cc66d0fd --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/XmlMapper.xml @@ -0,0 +1,30 @@ + + + + + + + + + insert into users (id, color) values (#{id}, #{color}) + + + diff --git a/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/mybatis-config.xml b/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/mybatis-config.xml index 9f909af819a..08d4486cfd3 100644 --- a/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/mybatis-config.xml +++ b/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/mybatis-config.xml @@ -1,7 +1,7 @@ + + + + + + + + + insert into users + values (#{id}, #{name}, #{cur}) + + + diff --git a/src/test/java/org/apache/ibatis/submitted/enum_with_method/User.java b/src/test/java/org/apache/ibatis/submitted/enum_with_method/User.java new file mode 100644 index 00000000000..2df46dc3796 --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/enum_with_method/User.java @@ -0,0 +1,47 @@ +/** + * Copyright 2009-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ibatis.submitted.enum_with_method; + +public class User { + + private Integer id; + private String name; + private Currency cur; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Currency getCur() { + return cur; + } + + public void setCur(Currency cur) { + this.cur = cur; + } +} diff --git a/src/test/java/org/apache/ibatis/submitted/enum_with_method/mybatis-config.xml b/src/test/java/org/apache/ibatis/submitted/enum_with_method/mybatis-config.xml new file mode 100644 index 00000000000..8e36f05c986 --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/enum_with_method/mybatis-config.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + +