3232 * {@link PropertyValueConverter converter} retrieval.
3333 *
3434 * @author Christoph Strobl
35+ * @author Mark Paluch
3536 * @since 2.7
3637 */
3738public class SimplePropertyValueConversions implements PropertyValueConversions , InitializingBean {
@@ -55,6 +56,18 @@ public PropertyValueConverterFactory getConverterFactory() {
5556 return converterFactory ;
5657 }
5758
59+ private PropertyValueConverterFactory obtainConverterFactory () {
60+
61+ PropertyValueConverterFactory factory = getConverterFactory ();
62+
63+ if (factory == null ) {
64+ throw new IllegalStateException (
65+ "PropertyValueConverterFactory is not set. Make sure to either set the converter factory or call afterPropertiesSet() to initialize the object." );
66+ }
67+
68+ return factory ;
69+ }
70+
5871 /**
5972 * Set the {@link ValueConverterRegistry converter registry} for path configured converters. This is short for adding
6073 * a
@@ -78,7 +91,7 @@ public ValueConverterRegistry<?> getValueConverterRegistry() {
7891 }
7992
8093 /**
81- * Dis-/Enable caching . Enabled by default.
94+ * Configure whether to use converter cache . Enabled by default.
8295 *
8396 * @param converterCacheEnabled set to {@literal true} to enable caching of {@link PropertyValueConverter converter}
8497 * instances.
@@ -89,14 +102,14 @@ public void setConverterCacheEnabled(boolean converterCacheEnabled) {
89102
90103 @ Override
91104 public boolean hasValueConverter (PersistentProperty <?> property ) {
92- return this . converterFactory .getConverter (property ) != null ;
105+ return obtainConverterFactory () .getConverter (property ) != null ;
93106 }
94107
95108 @ Nullable
96109 @ Override
97110 public <DV , SV , C extends PersistentProperty <C >, D extends ValueConversionContext <C >> PropertyValueConverter <DV , SV , D > getValueConverter (
98111 C property ) {
99- return this . converterFactory .getConverter (property );
112+ return obtainConverterFactory () .getConverter (property );
100113 }
101114
102115 /**
@@ -125,7 +138,7 @@ public void init() {
125138 }
126139
127140 @ Override
128- public void afterPropertiesSet () throws Exception {
141+ public void afterPropertiesSet () {
129142 init ();
130143 }
131144}
0 commit comments