blank == null

This commit is contained in:
Anthony Stirling
2023-10-07 23:35:28 +01:00
parent f4a01884bd
commit d94eca4ee7
4 changed files with 6 additions and 66 deletions

View File

@@ -9,17 +9,6 @@ import stirling.software.SPDF.model.ApplicationProperties;
@Configuration
public class AppConfig {
@Bean
public CustomEditorConfigurer customEditorConfigurer() {
return new CustomEditorConfigurer();
}
@Bean
public PropertyEditorRegistrar propertyEditorRegistrar() {
return registry -> {
registry.registerCustomEditor(String.class, new EmptyStringAsNullEditor());
};
}
@Autowired
ApplicationProperties applicationProperties;

View File

@@ -1,42 +0,0 @@
package stirling.software.SPDF.config;
import java.beans.PropertyEditor;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.validation.DataBinder;
public class CustomEditorConfigurer implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof PropertyEditorRegistrar) {
((PropertyEditorRegistrar) bean).registerCustomEditors(new PropertyEditorRegistry() {
@Override
public void registerCustomEditor(Class<?> requiredType, String propertyPath, java.beans.PropertyEditor propertyEditor) {
DataBinder dataBinder = new DataBinder(bean);
dataBinder.registerCustomEditor(requiredType, propertyPath, propertyEditor);
}
@Override
public void registerCustomEditor(Class<?> requiredType, java.beans.PropertyEditor propertyEditor) {
DataBinder dataBinder = new DataBinder(bean);
dataBinder.registerCustomEditor(requiredType, propertyEditor);
}
@Override
public PropertyEditor findCustomEditor(Class<?> requiredType, String propertyPath) {
return null;
}
});
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
}

View File

@@ -1,13 +0,0 @@
package stirling.software.SPDF.config;
import java.beans.PropertyEditorSupport;
public class EmptyStringAsNullEditor extends PropertyEditorSupport {
@Override
public void setAsText(String text) {
if (text != null && text.trim().isEmpty()) {
setValue(null);
} else {
setValue(text);
}
}
}