diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/EntityConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/EntityConverter.java index 4b96d0cd7d0..c085eb3844b 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/EntityConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/EntityConverter.java @@ -18,7 +18,6 @@ package org.springframework.core.convert.support; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; import org.springframework.util.ClassUtils; @@ -34,9 +33,9 @@ import org.springframework.util.ReflectionUtils; */ final class EntityConverter implements ConditionalGenericConverter { - private ConversionService conversionService; + private GenericConversionService conversionService; - public EntityConverter(ConversionService conversionService) { + public EntityConverter(GenericConversionService conversionService) { this.conversionService = conversionService; } @@ -56,6 +55,9 @@ final class EntityConverter implements ConditionalGenericConverter { } public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + if (source == null) { + return this.conversionService.convertNullSource(sourceType, targetType); + } if (String.class.equals(targetType.getType())) { Method idAccessor = getIdAccessor(sourceType.getType()); Object id = ReflectionUtils.invokeMethod(idAccessor, source); diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java index ef91679d18b..36e3090f884 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java @@ -20,7 +20,6 @@ import java.util.HashSet; import java.util.Set; import org.springframework.core.convert.converter.Converter; -import org.springframework.util.StringUtils; /** * Converts String to a Boolean. @@ -50,8 +49,8 @@ final class StringToBooleanConverter implements Converter { } public Boolean convert(String source) { - String value = (source != null ? source.trim() : null); - if (!StringUtils.hasLength(value)) { + String value = source.trim(); + if (value.length() == 0) { return null; } else if (trueValues.contains(value)) { diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java index 7e3525eab7b..3771d83f505 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java @@ -27,7 +27,7 @@ import org.springframework.core.convert.converter.Converter; final class StringToCharacterConverter implements Converter { public Character convert(String source) { - if ("".equals(source)) { + if (source.length() == 0) { return null; } if (source.length() > 1) { diff --git a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java index 181ba2430cf..b3d47d6a511 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java +++ b/org.springframework.core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java @@ -41,7 +41,7 @@ final class StringToEnumConverterFactory implements ConverterFactory