Hello everyone,
I think I had a solution for the following problem some time ago but I can’t think of one right now, so here I am:
I have the following structure:
sealed class ApiResult {
data class Error(val errors: List<ApiError>) : ApiResult() {
data class ApiError(
val propertyName: String,
val errorMessage: String,
val errorCode: String,
)
}
}
And I want to serialize some response json into
ApiResult.Error
.
The Json looks like that:
[
{
"propertyName": "...",
"errorMessage": "...",
"errorCode": "..."
}
]
So I have an object with holds a list of elements. Instantiating the object manually would look like that:
ApiResult.Error(objectMapper.readValue(""))
But I want to serialize directly into
ApiResultError
.
Usually I would do something along the lines of:
class ApiErrors: ArrayList<ApiErrors.ApiError>() {
data class ApiError(
val propertyName: String,
val errorMessage: String,
val errorCode: String,
)
So, implementing the ArrayList. This does not work inside a sealed class.
Any idea? Thanks in advance!