Trimming of char fields when using mapToBean

42 views
Skip to first unread message

Dave Nock

unread,
Feb 27, 2020, 8:54:41 PM2/27/20
to jDBI
Hi,

Is there an easy way to automatically trim char fields when using mapToBean()?
I know we can create RowMappers and do this manually, but I'm trying to reduce the amount of unnecessary code.

Have looked at other similar libraries and they seem to do this by default.

Thanks.
Dave

Steven Schlansker

unread,
Feb 28, 2020, 1:27:50 PM2/28/20
to jd...@googlegroups.com
Generally, jdbi tries not to transform your data behind your back. That means if a string has leading or trailing spaces, we preserve them.

What kind of char field do you have? You don't actually mean char[] right? The database vendor, column type, sql query also can all affect preservation of trailing spaces.

The "fix" might be as simple as changing your column type or adding a cast.
For example check out the Postgres rules around trailing spaces: https://www.postgresql.org/docs/12/datatype-character.html

You might also be able to cobble together an @Trimmed decorating annotation using the new Qualifier support, but that's a bit more work...
> --
> You received this message because you are subscribed to the Google Groups "jDBI" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+uns...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jdbi/4a989084-6adb-41a8-b533-da7f7ae2896b%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages