我有以下请求JSON正文:
在后端我有这个REST方法:
@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如下所示:
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;
}
restIntervalContainerWrapper- object at rest方法不为null,但字段不为null。如果我在休息服务方法中使用String而不是ScheduleIntervalContainerWrapper-对象而不是JSON-String就可以了 - 因此JacksonMapper无法映射字段,但我不知道为什么。 有谁知道我做错了什么? 非常感谢!
答案 0 :(得分:1)
杰克逊无法将您的JSON映射到对象中,因为您的JSON包含在ScheduleIntervalContainerWrapper
的字段中找不到的单个元素,即scheduleIntervalContainerWrapper
。
您可以使用
使用Jackson打开您的JSONmapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
并使用@JsonRootName(value = "scheduleIntervalContainerWrapper");
或者您只需发送没有包装器的JSON:
{"start" : "13.10.2015", "end" : "13.10.2015", "startTime": "7.0", "endTime" : "19.0"}