【问题标题】:Deserialization issue in abtract class with having a relation with an another class抽象类中与另一个类有关系的反序列化问题
【发布时间】:2019-09-14 04:59:17
【问题描述】:

我正在开发一个应用程序 angular 6 / spring boot。我有以下关系: 当我尝试持久化 Quote 对象时,如果 Customer 对象为空,它会起作用。但是,如果我想与客户保持 Quote 对象,我会收到消息:

@实体 @遗产 公共抽象类 Customer 实现 Serializable{

/**
 * 
 */
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long idCustomer;
@Column(unique = true)
@NotNull
private String code;
private String name;
private String address;
private String email;
private String phone;
private String city;
@OneToMany(mappedBy="customer")
private List<Order> orders;
private byte status;
@OneToMany(mappedBy="customer")
private List<Quote> quote;
@JoinColumn(name="country")
@ManyToOne
private Country country;

@Entity
public class Individual extends Customer{

private String firstname;
private String gender;

@Entity
public class Company extends Customer implements Serializable{
private static final long serialVersionUID = 1L;
@NotNull
private String legalForm;

@Entity
public class Quote implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long idQuote;
private LocalDate dateQuote;
@OneToMany(fetch = FetchType.EAGER, mappedBy="quote", 
cascade=CascadeType.ALL)
private List<QuoteLine> items;
@ManyToOne
@JoinColumn(name="id_customer",nullable=false)
private Customer customer;

com.fasterxml.jackson.databind.exc.InvalidDefinitionException:无法构造com.pam.entities.Customer 的实例(没有创建者,如默认构造,存在):抽象类型要么需要映射到具体类型,要么具有自定义反序列化器,要么包含附加类型信息

【问题讨论】:

    标签: angular spring


    【解决方案1】:

    您需要使用默认构造函数和setter getter 方法。是你写的吗?

    【讨论】:

    • 构造函数在哪里?
    • 在你里面 POJO 类 Company.ajav Quote.java
    • 是的,我在所有类中都有默认构造函数和 setter/getter
    • Ok.. 你可以尝试将给定的注释放在 Company.java 类上的类级别。 @JsonDeserialize(as = Company.class)
    • 我试了一下,但我有同样的错误:在 [Source: (PushbackInputStream);行:1,列:460](通过参考链:com.pam.entities.Quote["customer"])] 根本原因 ....
    猜你喜欢
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    • 2010-10-12
    • 1970-01-01
    • 2017-11-06
    • 2011-04-07
    • 1970-01-01
    相关资源
    最近更新 更多