I'm added an enum type and variable to one of my classes. Have a spring boot tests written which are using this class.
Once the enum was added, jacksonMapper isn't able to convert the class (for the restTemplate POST request).
Here is the error:
2016-11-17 11:36:11.571 WARN 10000 --- [o-auto-1-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of com.springapp.models.common.Condo: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: java.io.PushbackInputStream@6393fabb; line: 1, column: 2]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.springapp.models.common.Condo: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: java.io.PushbackInputStream@6393fabb; line: 1, column: 2]
2016-11-17 11:36:11.639 INFO 10000 --- [ main] c.s.controllers.api.CondoControllerTest : status: 400
2016-11-17 11:36:11.639 INFO 10000 --- [ main] c.s.controllers.api.CondoControllerTest : message: Could not read document: Can not construct instance of com.springapp.models.common.Condo: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: java.io.PushbackInputStream@6393fabb; line: 1, column: 2]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.springapp.models.common.Condo: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: java.io.PushbackInputStream@6393fabb; line: 1, column: 2]
the class:
public class Condo {
**irrelevant fields**
public Condo(LocationType locationType) {
this.locationType = locationType;
}
public enum LocationType {
CONDO("condo"), MALL("mall"), STATION("station");
private String value;
private LocationType(String value) {
this.value = value;
}
public String stringValue() {
return this.value;
}
}
public LocationType getLocationType() {
return locationType;
}
LocationType locationType;
** getters/setters**
}
i also tried to use @JsonCreator, @jsonValue as it is pointed at some other SO threads. Doesn't help,
request:
Condo condo = new Condo(Condo.LocationType.CONDO);
** setting fields for condo object **
//CREATE
ResponseEntity<JsonResponse> responseEntity = restTemplate.postForEntity(controllerPath+"/add_active", condo, JsonResponse.class);
Check your controller code if you don't have Condo as input parameter. From the log it seems so. Jackson cannot deserialize the HTTP representation of Condo because it does not have default constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With