Hi there I have question about contract control for my controller.
My entity have 2 required fields and 2 optional but all of them are notnullable
When client send request with
name=null
or
description=null
, processing fails onto json
MissingKotlinParameterException: Instantiation of [simple type, class com.norselab.ivaldi.model.category.Category] value failed for JSON property name due to missing (therefore NULL)
but if missed optional (not description=null, but missed in request from client) field - it instantiated from default value, in the same if missed required field also comes miss json error and status 500, but probably good is to have status 400
Is this expected behavior? Or I have miss configuration or even miss understanding
data class Category(
val externalId: String = UUID.randomUUID().toString(),
val name: String,
val description: String = "",
val parent: String = ""
)
class Controller {
@PostMapping("")
fun createCategory(@RequestBody newCategory: Category) {}
}
or this is bad practice