无法转换值[null]的参数[model],原因是:无法构造'view.model.product.productviewmodel'的示例`

o4tp2gmn  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(424)

我在Micronaut2.2.1中使用Java15记录功能,序列化不起作用

{
    "message": "Failed to convert argument [model] for value [null] due to: Cannot construct instance of `view.model.product.ProductViewModel` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)\n at [Source: UNKNOWN; line: -1, column: -1]",
    "path": "/model",
    "_links": {
        "self": {
            "href": "/api/v1/product",
            "templated": false
        }
    }
}

productviewmodel记录

public record ProductViewModel
        (
                @Nullable
                @JsonProperty("id")
                String id,

                @Nullable
                @JsonProperty("name")
                String name,

                @Nullable
                @JsonProperty("description")
                String description,

                @Nullable
                @JsonProperty("price")
                float price
        ) {
}

控制器

public Single<HttpResponse<?>> Create(@Body ProductViewModel model) {
        LOG.info(String.format("Controller --> Creating new product"));
        return iProductManager.Create(model).map(item -> HttpResponse.created(item));
    }
14ifxucb

14ifxucb1#

我失踪了 @Introspected 记录中的注解

@Introspected
public record ProductViewModel
        (
                @JsonProperty("id")
                String id,

                @JsonProperty("name")
                String name,

                @JsonProperty("description")
                String description,

                @JsonProperty("price")
                Float price
        ) {
}

相关问题