Hi there I have question about contract control fo...
# spring
m
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
Copy code
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
e
do you include and configure jackson-kotlin-module?
m
yeap (spring boot 2.0.3 jackson 2.9.6)
e
hm..I thought it worked, but it don’t and I found issue: https://github.com/FasterXML/jackson-module-kotlin/issues/130
i think that simplest solution is not send null values at json at all