I am using Java 15 record feature with Micronaut 2.2.1, the serialization is not working
{
"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 Record
public record ProductViewModel
(
@Nullable
@JsonProperty("id")
String id,
@Nullable
@JsonProperty("name")
String name,
@Nullable
@JsonProperty("description")
String description,
@Nullable
@JsonProperty("price")
float price
) {
}
Controller
public Single<HttpResponse<?>> Create(@Body ProductViewModel model) {
LOG.info(String.format("Controller --> Creating new product"));
return iProductManager.Create(model).map(item -> HttpResponse.created(item));
}
I was missing
@Introspected
annotation in record