模型映射器映射通用字段
我正在使用 ModelMapeer 库并尝试添加自定义映射。 我有抽象实体:
public abstract class AbstractEntity<ID extends Serializable> {
private ID id;
}
和子实体,
public class User extends AbstractEntity<UUID> {
//fields
}
所以我尝试添加这样的自定义映射
this.typeMap(User.class, UserDetailsDto.class)
.addMappings(mapper -> mapper.map(User::getId, UserDetailsDto::userId));
并得到此异常:
java.lang.ClassCastException: class java.io.Serializable$ByteBuddy$lX3s11ID cannot be cast to class java.util.UUID
我需要在映射(而不是实体)中更改什么来解决此问题?谢谢!
I am using ModelMapeer library and trying to add a custom mapping.
I have abstract entity:
public abstract class AbstractEntity<ID extends Serializable> {
private ID id;
}
and child entity
public class User extends AbstractEntity<UUID> {
//fields
}
so I am trying to add custom mapping like this
this.typeMap(User.class, UserDetailsDto.class)
.addMappings(mapper -> mapper.map(User::getId, UserDetailsDto::userId));
and getting this exception:
java.lang.ClassCastException: class java.io.Serializable$ByteBuddy$lX3s11ID cannot be cast to class java.util.UUID
What do I need to change in a mapping(not entities) to resolve this? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为
UserDetailsDto.userId
是UUID
,而User.id
是Serialized
Id。两者不兼容。I think
UserDetailsDto.userId
isUUID
andUser.id
isSerializable
Id. Both are not compatible.