Reputation: 5733
I have the following request JSON body:
and at backend I have this REST method:
@JsonView(RestServiceResponseView.InstitutionUserConnectionAndSchedulerPublic.class)
@RequestMapping(value = "/schedules/{institutionuserconnectionid}", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody List<ScheduleResponseWrapper> createScheduleIntervalContainers(
@PathVariable(value = "institutionuserconnectionid")
final String institutionUserConnectionId,
final @RequestBody(required = true) ScheduleIntervalContainerWrapper scheduleIntervalContainerWrapper) throws BusinessException {
ScheduleIntervalContainerWrapper looks like this:
public class ScheduleIntervalContainerWrapper implements Serializable {
private static final long serialVersionUID = 5430337066683314866L;
private String start;
private String end;
private String startTime;
private String endTime;
public ScheduleIntervalContainerWrapper() {
}
public String getStart() {
return start;
}
public void setStart(final String start) {
this.start = start;
}
public String getEnd() {
return end;
}
the ScheduleIntervalContainerWrapper- object at rest method is not null but the fields are not null. If I use a String instead of ScheduleIntervalContainerWrapper- object at rest service method than JSON- String is ok - therefore JacksonMapper can not map the fields but I don't know why. Does anyone know what I am doing wrong? Thanks a lot!
Upvotes: 0
Views: 1036
Reputation: 61
Jackson cannot map your JSON into the object because your JSON contains a single element that is not found within the fields of ScheduleIntervalContainerWrapper
namely scheduleIntervalContainerWrapper
.
You can either use Jackson to unwrap your JSON, using
mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
and annotating your model with @JsonRootName(value = "scheduleIntervalContainerWrapper");
Or you could simply send the JSON without the wrapper :
{"start" : "13.10.2015", "end" : "13.10.2015", "startTime": "7.0", "endTime" : "19.0"}
Upvotes: 1