You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is your use-case and why do you need this feature?
I have a Spring Boot REST API and I want to control what error codes are returned if there's a problem with some JSON.
At the moment I use Jackson, and in a @ControllerAdvice class I can handle the Jackson exceptions. They provide specific data about the JSON mapping failure.
I can't do this with Kotilnx Serialization because the exceptions are internal, and data about the exceptions gets concatenated into a string.
@ExceptionHandler(kotlinx.serialization.SerializationException::class)
funhandleKotlinxSerializationException(exception:SerializationException): ResponseEntity<Any> {
when (exception) {
// ERROR Cannot access 'MissingFieldException': it is internal in 'kotlinx.serialization'is kotlinx.serialization.MissingFieldException->...
}
}
Describe the solution you'd like
I'd like to do the same with the Kotlinx Serialization exceptions. Here are some suggestions:
make the existing exceptions public, and add fields so I can access the exact problem
@PublishedApi
publicclassMissingFieldException( // make publicvalfieldNames:List<String>, // expose the specific problemvalcause:Exception?,
) : SerializationException("Field ... was missing...", cause)
Keep the exceptions internal, but provide some public data class and add it to SerializationException
sealedinterfaceSerializationExceptionDetail {
data classMissingFields(
valmissingFields:List<String>
): SerializationExceptionDetail
data classUnknownField(
valunknownFields:List<String>
): SerializationExceptionDetail
// ...
}
And add the detail to the existing public exception
What is your use-case and why do you need this feature?
I have a Spring Boot REST API and I want to control what error codes are returned if there's a problem with some JSON.
At the moment I use Jackson, and in a
@ControllerAdvice
class I can handle the Jackson exceptions. They provide specific data about the JSON mapping failure.I can't do this with Kotilnx Serialization because the exceptions are internal, and data about the exceptions gets concatenated into a string.
Describe the solution you'd like
I'd like to do the same with the Kotlinx Serialization exceptions. Here are some suggestions:
SerializationException
Related:
The text was updated successfully, but these errors were encountered: