AutoValue对象作为控制器中的GET

时间:2018-09-29 19:16:18

标签: spring-mvc spring-data-rest auto-value

嗨,我无法在Spring控制器的GET端点中将AutoValue对象用作参数对象。但是,POST可以正常工作。可以将自动值与GET端点一起使用吗?

谢谢, 豪尔赫

@AutoValue
@JsonDeserialize(builder = AutoValue_InformeCampoCreateRequest.Builder.class)
public abstract class InformeCampoCreateRequest {
    @NotNull
    @JsonProperty("id")
    public abstract long id();

    @NotNull
    public static Builder builder() {
        return new AutoValue_InformeCampoCreateRequest.Builder();
    }

    @AutoValue.Builder
    public static abstract class Builder {

        @NotNull
        @JsonProperty("id")
        public abstract Builder id(@NotNull long id);

        @NotNull
        public abstract InformeCampoCreateRequest build();
    }
}

并且我将此端点与对象作为GET参数

@GetMapping(value = "/informes")
public ResponseEntity<?> create(InformeCampoCreateRequest informeCampoCreateRequest) {

    return ok(null);
}

然后Spring抱怨:

org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.almundo.api.flights.worldspan.availability.presentation.InformeCampoCreateRequest]: Is it an abstract class?; nested exception is java.lang.InstantiationException\n\tat org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:173)\n\tat org.springframework.web.method.annotation.ModelAttributeMethodProcessor.constructAttribute(ModelAttributeMethodProcessor.java:243)\n\tat org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:217)\n\tat org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:84)\n\tat org.sp

0 个答案:

没有答案