Eivind
01/31/2022, 4:11 PMmkrussel
01/31/2022, 4:15 PMmessage
must always match what was passed in.
You could make it private and then expose a different property as public based on the constructor logic.Joffrey
01/31/2022, 4:15 PMinit { }
block in the class with code that checks the message and throws if it doesn't match the expectations.
If you want to transform the assigned message, then maybe this class is not a simple data holder. What would you expect ApiError.copy(message = "new message")
to do? Should it transform the message as well? Should 2 `ApiError`s created with different messages but having the same underlying transformed message be considered equal? Should toString()
reflect the original or the transformed message?
Maybe you could consider making it a regular class and assign the message
property after transformation:
class ApiError(message: String) {
val message = transform(message)
}
mkrussel
01/31/2022, 4:16 PMEivind
02/01/2022, 8:17 AMString.replace("\n", System.lineSeparator())
but it didn't really work. Any suggestion? I figure this has something to do with Jackson / the default serializer kotlin/spring boot is using?Joffrey
02/01/2022, 8:52 AM\n
and \r
) in JSON strings. They have to in order to conform to the spec. What you probably want (if you really want to change those) is to change the contents of the message before serializationEivind
02/01/2022, 8:55 AMthis is a string\r\n This is an indented line\r\n This is another indented line
. I'd like to format it to look the way it says it looks, but that's proving difficult. I don't know why it is like that.Joffrey
02/01/2022, 8:56 AMEivind
02/01/2022, 8:58 AMJoffrey
02/01/2022, 9:01 AMEivind
02/01/2022, 9:05 AMn
sub-errors (yes they're all a part of the same string). I guess any users wanting a more readable message should just format it themselves (I only develop the api).Joffrey
02/01/2022, 9:09 AM\r
and \n
in thereEivind
02/01/2022, 9:31 AM