Philipp Mayer
08/31/2021, 1:28 PMsealed 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!dinomite
08/31/2021, 2:49 PMdinomite
08/31/2021, 2:49 PMError
object transparentPhilipp Mayer
08/31/2021, 2:58 PM@JsonCreator
is not applicable to target ‘class’dinomite
08/31/2021, 3:14 PMdinomite
08/31/2021, 3:14 PMPhilipp Mayer
08/31/2021, 3:20 PMdinomite
08/31/2021, 3:54 PM