java - 带有抽象类的推土机映射
问题描述
我正在使用推土机通过注释方法在 bean 和模型之间进行映射。一切都适用于大多数课程。
但是最近当我的 bean 使用 1 个参数保护构造函数时,我遇到了 1 个问题。因为这个构造函数在某些地方使用了super
关键字。
下面是示例示例:
TestBean.java:
abstract public class TestBean{
public enum Type {
ALL, FIELD, QUERY, HIERARCHY
}
public enum Sort {
COUNT, INDEX, VALUE
}
private Type type;
private String description;
private Sort sort;
public FacetBean() {
}
protected FacetBean(FacetBean from) {
setId(from.getId());
description = from.description;
sort = from.sort;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Sort getSort() {
return sort;
}
public void setSort(Sort sort) {
this.sort = sort;
}
}
下面是我的模型的示例代码。
测试模型.java
public class TestModel{
public enum Type {
ALL, FIELD, QUERY, HIERARCHY
}
public enum Sort {
COUNT, INDEX, VALUE
}
private Type type;
private String description;
private Sort sort;
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Sort getSort() {
return sort;
}
public void setSort(Sort sort) {
this.sort = sort;
}
}
我正在使用org.dozer.mapper
模型和bean之间的映射。
以下是工作代码:
mapper.map(testBean, TestModel.class)
-->工作
如果我反过来尝试,那么它给了我
mapper.map(testModel, TestBean.class)
->不工作
org.dozer.MappingException: java.lang.InstantiationException
知道如何解决这个问题吗?(我无法更改 TestBean.java,因为它是一个非常古老的类并且在很多地方使用,我最近创建了 TestModel.java 来将 TestBean.java 的数据映射到它并作为 API 响应返回)
谢谢!
解决方案
推荐阅读
- c# - Blazor WASM“无法反序列化当前 JSON 对象(例如 {"name":"value"})”错误
- java - 如何为以编程方式存储在变量中的按钮添加 android 可绘制文件的值?
- javascript - Javascript - 添加通用文档事件侦听以捕获任何事件?
- clickhouse - 如何通过 S3 磁盘上的 clickhouse 检查内存空间使用情况?
- c++ - 为什么 std::mutex 在 Visual C++ 中比 std::shared_mutex 差这么多?
- azure-cognitive-services - Microsoft 自定义翻译器 - 系统维护后模型的取消部署
- c# - 实体框架核心 - EnableIdentityInsert
- r - 执行独立样本 t 检验
- jolt - JOLT - 组合数组并添加父键的属性
- ssh - Ansible 无法访问本地主机