Iโm creating a validation handler function. I want it to return
{
"description": [
"The field Description must be no more than 25 characters long",
"The field Description must be at least 6 characters long"
],
"title": [
"The field Title must be between 6 and 25 characters long"
]
}
This is my code :
val errorMap: MutableMap<String, ArrayList<String>> = HashMap()
val stringArray: ArrayList<String> = ArrayList()
e.bindingResult.fieldErrors.forEach(Consumer { error: FieldError ->
error.defaultMessage?.let { stringArray.add(it) }
errorMap[error.field] = stringArray
})
But it returns:
{
"description": [
"The field Title must be between 6 and 25 characters long",
"The field Description must be no more than 25 characters long",
"The field Description must be at least 6 characters long"
],
"title": [
"The field Title must be between 6 and 25 characters long",
"The field Description must be no more than 25 characters long",
"The field Description must be at least 6 characters long"
]
}
Whatโs the most elegant to to that with Kotlin ?