[英]Rest Request not mapped to object
我有以下請求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;
}
ScheduleIntervalContainerWrapper-靜態對象方法不為null,但字段也不為null。 如果我在休息服務方法中使用String而不是ScheduleIntervalContainerWrapper-對象而不是JSON- String是可以的-因此JacksonMapper無法映射字段,但我不知道為什么。 有人知道我在做什么錯嗎? 非常感謝!
Jackson無法將JSON映射到對象中,因為JSON包含一個在ScheduleIntervalContainerWrapper
字段中找不到的元素,即scheduleIntervalContainerWrapper
。
您可以使用Jackson來解包JSON,方法是:
mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
並使用@JsonRootName(value = "scheduleIntervalContainerWrapper");
注釋模型@JsonRootName(value = "scheduleIntervalContainerWrapper");
或者,您可以直接發送不帶包裝的JSON:
{"start" : "13.10.2015", "end" : "13.10.2015", "startTime": "7.0", "endTime" : "19.0"}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.