我正在使用具有预期依赖项(Jackson、Hibernate 等)的 Spring Boot。
我有一个名为 Buildings 的表,其中 Unit、Number、Street 等都是列。但我更喜欢解析它并将其作为我创建的名为“StreetAddress”的类返回。
当我发送此 JSON 时,出现错误。
"address": {
"unit":"0101",
"number":"19",
"suffix":"STREET",
"suburb":"Example",
"state":"EXP",
"streetName":"Example",
"postCode":"400"
}
这是错误:
Cannot construct instance of `com.App.Entity.Helpers.StreetAddress` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
我在我的建筑模型中将其作为 setAddress。有没有我可以用来告诉杰克逊如何正确解析的注释?
private String subunit;
private Integer number;
private String streetname;
private String suffix;
private String suburb;
private String state;
private Integer postcode;
public void setAddress(StreetAddress address) {
this.subunit = address.getUnit();
this.number = address.getNumber();
this.streetname = address.getStreetName();
this.suffix = address.getSuffix().toString();
this.suburb = address.getSuburb();
this.state = address.getState().toString();
this.postcode = address.getPostCode();
}
澄清:
public class StreetAddress {
private String unit;
private Integer number;
private String streetname;
private StreetSuffix suffix;
private String suburb;
private AUState state;
private Integer postcode;
public StreetAddress(String unit, int number, String street, StreetSuffix suffix, String suburb, AUState state, int postcode) {
this.unit = unit;
this.number = number;
this.streetname = street;
this.suffix = suffix;
this.suburb = suburb;
this.state = state;
this.postcode = postcode;
}
public String getUnit() {
return unit;
}
public Integer getNumber() {
return number;
}
public String getStreetName() {
return streetname;
}
public String getSuffix() {
return suffix.toString();
}
public String getSuburb() {
return suburb;
}
public AUState getState() {
return state;
}
public Integer getPostCode() {
return postcode;
}
}
慕无忌1623718
相关分类