I seem to have found a configuration which supports Null values for empty Strings. For my @Controller I stick with the StringTrimmerEditor
in my @ControllerAdvice
. Nothing new here.
For SWF ConversionService
seems to do the trick: First I create a Converter
which converts "" into Null:
public class StringToNullConverter implements Converter<String, String> {
@Override
public String convert(String source) {
if (StringUtils.isEmpty(source)) {
return null;
}
return source;
}
}
Now I have to register this in Spring:
import org.springframework.core.convert.*;
@Configuration
public class SpringConfiguration {
@Bean public ConversionService conversionService() {
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
conversionService.addConverter(new StringToNullConverter());
return conversionService;
}
}
Until now nothing new happens and we're talking about the org.springframework.core.convert
package. Now comes the SWF glue into the org.springframework.binding.convert
package:
import org.springframework.binding.convert.*;
@Bean public ConversionService flowConversionService(org.springframework.core.convert.ConversionService conversionService) {
DefaultConversionService service = new DefaultConversionService(conversionService);
return service;
}
Wire this into SWF with
<webflow:flow-builder-services [..] conversion-service="flowConversionService" />
.
This looks a bit too much, but it does the job. I'm sure there must be a better way, as I have two different implementations (StringTrimmerEditor
and StringToNullConverter
) to achieve the same thing. For me it looks like ConversionService
seems to be the one and only way to go. But I didn't figure out how to get it done for a Spring @Controller
.