I'm using Spring Boot with the expected dependencies (Jackson, Hibernate etc.).
I'm have a table called Buildings where Unit, Number, Street etc. are all columns. But I prefer to parse this and return this as a class I created called "StreetAddress".
When I send this JSON, I get an error.
"address": {
"unit":"0101",
"number":"19",
"suffix":"STREET",
"suburb":"Example",
"state":"EXP",
"streetName":"Example",
"postCode":"400"
}
This is the error:
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)
I have this as setAddress in my Building model. Is there any annotation I can use to tell Jackson how to parse this properly?
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();
}
Clarification:
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;
}
}