andyb
04/27/2018, 10:24 PMfun getCustomer(@PathVariable customerId: String): ResponseEntity<Either<ErrorResponse, CustomerResponse>> {
val result = Try { getCustomerService.getCustomer(customerId) }
return result.fold({ err -> ResponseEntity(Either.Left(ErrorResponse()), HttpStatus.INTERNAL_SERVER_ERROR) },
{ customer -> ResponseEntity(Either.Right(CustomerResponse(customer)), HttpStatus.OK) }
)
}
This looks ok but obviously the JSON in the response has the full contents of Either.Right e.g. {"b":{"customer": ... },"right$arrow_core":true,"left$arrow_core":false,"left":false,"right":true}
Is there an easy way to override the MappingJackson2HttpMessageConverter
so that it contains the value in the Right/Left rather than the full object?