【发布时间】:2019-02-10 11:48:56
【问题描述】:
Spring boot 2 rest api 不序列化映射超类继承。
我使用 Spring boot 2.1.2.RELEASE 和 PagingAndSortingRepository。 我的 appconfig 是:
jackson:
serialization:
WRITE_DATES_AS_TIMESTAMPS: false
deserialization:
FAIL_ON_READING_DUP_TREE_KEY: true
ACCEPT_EMPTY_STRING_AS_NULL_OBJECT: true
parser:
STRICT_DUPLICATE_DETECTION: true
我的映射超类是:
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@MappedSuperclass
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS,
include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = EmployeeUnit.class, name = "EmployeeUnit")
})
public class AbstractDomain {
...
}
儿童班:
@Data
@NoArgsConstructor
@Entity
@Table(name = EmployeeUnit.TABLE_NAME)
@GenericGenerator(name="generator", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
parameters = {
@org.hibernate.annotations.Parameter(name = "sequence_name", value = "employee_unit_seq"),
@org.hibernate.annotations.Parameter(name = "initial_value", value = "1000"),
@org.hibernate.annotations.Parameter(name = "increment_size", value = "1")
})
@JsonTypeName("employeeUnit")
public class EmployeeUnit extends AbstractDomain {
}
输出是:
{
"name" : "Unit-Pecs-EA1",
"code" : "UPEA1",
"description" : "Pecs EA Unit 1",
"created" : "2019-02-10 12:34",
"edited" : "2019-02-10 12:34",
"_links" : {
"self" : {
"href" : "http://localhost:8480/api/v1/employeeUnit/1000"
},
"employeeUnit" : {
"href" : "http://localhost:8480/api/v1/employeeUnit/1000"
}
}
是否有其他配置设置来强制序列化映射的超类?
【问题讨论】: