-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeHandler to Map inappropriately invoked when method has multiple parameters #135
Comments
Hi again Luke. I added a test with a handler and two params but it did not fail. Have you been able to isolate the problem? Can you create a repo with a failing test? That will be really helpful. |
I was finally able to reproduce it. It only fails with annotations. Lets see what is happening. |
This is an interesting chain of side effects coming indeed from a bug originated in #98 Given this scenario:
A handler for Map.class
This is the sequence of problems: Execution Stage: So seems that we should fix [1] by just doing what I warnend on #98: telling the truth!: parameterType is ParamMap, not Map. Sorry for the long explanation but given this bug is complex I wanted to have the change documented. |
Wow, cool! |
I am facing the same issue. I have a nvarchar column in the database which has JSON content with key and value pairs. The mapped model has a Map field to retrieve the column, as you mentioned other column types are mapping to this handler and failing with Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map. FYI: I don't have @MappedTypes annotation on my handler. If I added the annotation @MappedTypes(Map.class), it has the same behavior failing with class cast exception. The API which has this map field in the model is working fine, but when we hit different API, it's going this handler and failing with class cast exception. Mybatis version: 3.4.5 |
If a TypeHandler for the Map class is registered, it gets invoked inappropriately when a mapper method uses multiple parameters.
For example, a TypeHandler:
Then these methods in the mapper interface:
The first method, with just one parameter, succeeds, while the second method fails with a stack trace that ends with:
The text was updated successfully, but these errors were encountered: