You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my example, because MyType doesn't have a field named i, only a constructor arg, then it doesn't successfully resolve the type of i and defaults to Object (see MapperBuilderAssistant#resolveResultJavaType).
I believe when @ConstructorArgs is used, then implicit type resolution should be run against the constructor arguments.
Workaround
Explicitly specify the Java type to use:
@Arg(column = "i", name = "i", javaType = Integer.class)
Side notes
Relates to #2207, although not exactly the same case I believe.
The text was updated successfully, but these errors were encountered:
Just FYI, another perhaps related issue: @MappedTypes on top of a TypeHandler isn't taken into account when @ConstructorArgs is used without explicitly specifying the Java types. I'm not 100% sure whether it should though.
This fails too with the same message as above, because the specified typeHandler isn't used when trying to resolve the type of i, which I believe it should.
Let me know if you believe this deserves its own ticket.
Constructors are identified by parameter types, not by argument names.
You can omit the javaType only when there is a writable property with the same name and type.
It's explained in the documentation.
MyBatis version
3.5.11
Steps to reproduce
Expected result
MyBatis should understand that
i
is expected to be of typeInteger
given it's the type of the matching argument in the constructor.Actual result
I get in the logs:
I believe this is due to the fact that
MapperAnnotationBuilder#applyConstructorArgs
callsMapperBuilderAssistant#buildResultMapping
, which tries to resolve the Java type by looking at the class' fields, instead of by looking at the constructor args as one could think given@ConstructorArgs
is used.In my example, because
MyType
doesn't have a field namedi
, only a constructor arg, then it doesn't successfully resolve the type ofi
and defaults toObject
(seeMapperBuilderAssistant#resolveResultJavaType
).I believe when
@ConstructorArgs
is used, then implicit type resolution should be run against the constructor arguments.Workaround
Explicitly specify the Java type to use:
Side notes
Relates to #2207, although not exactly the same case I believe.
The text was updated successfully, but these errors were encountered: