treat an empty string as a null character in CharacterJavaType conversion

an empty string should not be converted to a space char

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-10-30 10:28:47 +01:00
parent 26988dd536
commit 2924fe8875
1 changed files with 7 additions and 6 deletions

View File

@ -67,12 +67,13 @@ public class CharacterJavaType extends AbstractClassJavaType<Character> implemen
if (value instanceof Character character) {
return character;
}
if ( value instanceof String ) {
if ( value.equals( "" ) ) {
return ' ';
}
final String str = (String) value;
return str.charAt( 0 );
if (value instanceof String string) {
// Note that this conversion is "dangerous",
// since it is not invertible, and can in
// principle result in accidental loss of data.
// It might be better to throw if the incoming
// string does not have length one.
return string.isEmpty() ? null : string.charAt( 0 );
}
if (value instanceof Number number) {
return (char) number.shortValue();