What are the possible solutions for stripping the trailing whitespace when mapping char
fields in a legacy database?
I see the following options:
.trim()
at the point of use (controller, view, etc).trim()
I'm leaning toward overriding the property accessor so that the domain properties remain consistent throughout the application.
I had a similar problem and I could not alter the legacy data. I ended up overriding the accessor for the sake of transparency to my fellow developers. I would recommend using a transient field so you don't have to trim the String on every call. However; if you can just clean up the data in the table, create a view, or transfer to a new table I would do that instead.