简体   繁体   English

休息请求未映射到对象

[英]Rest Request not mapped to object

I have the following request JSON body: 我有以下请求JSON正文:

要求正文

and at backend I have this REST method: 在后端,我有以下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 looks like this: 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;
}

the ScheduleIntervalContainerWrapper- object at rest method is not null but the fields are not null. ScheduleIntervalContainerWrapper-静态对象方法不为null,但字段也不为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. 如果我在休息服务方法中使用String而不是ScheduleIntervalContainerWrapper-对象而不是JSON- String是可以的-因此JacksonMapper无法映射字段,但我不知道为什么。 Does anyone know what I am doing wrong? 有人知道我在做什么错吗? Thanks a lot! 非常感谢!

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 . Jackson无法将JSON映射到对象中,因为JSON包含一个在ScheduleIntervalContainerWrapper字段中找不到的元素,即scheduleIntervalContainerWrapper

You can either use Jackson to unwrap your JSON, using 您可以使用Jackson来解包JSON,方法是:

mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);

and annotating your model with @JsonRootName(value = "scheduleIntervalContainerWrapper"); 并使用@JsonRootName(value = "scheduleIntervalContainerWrapper");注释模型@JsonRootName(value = "scheduleIntervalContainerWrapper");

Or you could simply send the JSON without the wrapper : 或者,您可以直接发送不带包装的JSON:

{"start" : "13.10.2015", "end" : "13.10.2015", "startTime": "7.0", "endTime" : "19.0"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM