Java 使用getter方法时,我收到一个错误(HttpMessageNotWritableException:无法写入JSON:bean类的无效属性';')
我正在使用接口Java 使用getter方法时,我收到一个错误(HttpMessageNotWritableException:无法写入JSON:bean类的无效属性';'),java,spring,spring-boot,Java,Spring,Spring Boot,我正在使用接口loainterface.java根据请求显示值。我的问题是我遇到了以下错误: Invalid property 'accountNumber' of bean class [com.meteor.coral.portfolio.modules.loanaccount.domain.Loan$HibernateProxy$Vm2InzHB]: Getter for property 'accountNumber' threw exception; nested exception
loainterface.java
根据请求显示值。我的问题是我遇到了以下错误:
Invalid property 'accountNumber' of bean class [com.meteor.coral.portfolio.modules.loanaccount.domain.Loan$HibernateProxy$Vm2InzHB]:
Getter for property 'accountNumber' threw exception; nested exception is java.lang.reflect.InvocationTargetException;
nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid property 'accountNumber' of bean class
[com.meteor.coral.portfolio.modules.loanaccount.domain.Loan$HibernateProxy$Vm2InzHB]: Getter for property 'accountNumber' threw exception;
nested exception is java.lang.reflect.InvocationTargetException
(through reference chain: org.springframework.data.domain.PageImpl["content"]
->java.util.Collections$UnmodifiableRandomAccessList[0]->com.sun.proxy.$Proxy394["loanId"]->com.sun.proxy.$Proxy395["accountNumber"])]
这是我的loainterface.java
@JsonPropertyOrder({
"id",
"accountNumber"
})
public interface LoanInterface {
public Long getId();
public String getAccountNumber();
}
@JsonPropertyOrder({
"id",
"loanId"
})
public interface BillingProcessInterface {
public Long getId();
public LoanInterface getLoanId();
}
@Entity
@Table(name = "m_billing")
@Data
@EqualsAndHashCode(callSuper = true)
public class BillingProcess extends AbstractPersistableCustom<Long> {
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "loan_id", nullable = false)
private Loan loanId;
}
这是模型,Loan.java
,我想从中获取以下字段:
@Entity
@Component
@Data
@EqualsAndHashCode(callSuper = false)
@Table(name = "m_loan", uniqueConstraints = { @UniqueConstraint(columnNames = { "account_no" }, name = "loan_account_no_UNIQUE"),
@UniqueConstraint(columnNames = { "external_id" }, name = "loan_externalid_UNIQUE") })
public class Loan extends AbstractPersistableCustom<Long> {
@Column(name = "account_no", length = 20, unique = true, nullable = false)
private String accountNumber;
}
BillingProcess.java
model,其中我调用Loan.java
@JsonPropertyOrder({
"id",
"accountNumber"
})
public interface LoanInterface {
public Long getId();
public String getAccountNumber();
}
@JsonPropertyOrder({
"id",
"loanId"
})
public interface BillingProcessInterface {
public Long getId();
public LoanInterface getLoanId();
}
@Entity
@Table(name = "m_billing")
@Data
@EqualsAndHashCode(callSuper = true)
public class BillingProcess extends AbstractPersistableCustom<Long> {
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "loan_id", nullable = false)
private Loan loanId;
}
@实体
@表(name=“m_账单”)
@资料
@EqualsAndHashCode(callSuper=true)
公共类BillingProcess扩展了AbstractPersistableCustom{
@ManyToOne(可选=false,fetch=FetchType.LAZY)
@JoinColumn(name=“loan\u id”,nullable=false)
私人贷款;
}
来自loainterface.java
的getId
可以工作:
但是当我试图从Loan.java
中获取其他字段时,比如accountNumber
,我得到了错误
有人知道如何解决这个问题吗?我是否过度使用或缺少注释的使用?
多谢各位