32
32
* {@link PropertyValueConverter converter} retrieval.
33
33
*
34
34
* @author Christoph Strobl
35
+ * @author Mark Paluch
35
36
* @since 2.7
36
37
*/
37
38
public class SimplePropertyValueConversions implements PropertyValueConversions , InitializingBean {
@@ -55,6 +56,18 @@ public PropertyValueConverterFactory getConverterFactory() {
55
56
return converterFactory ;
56
57
}
57
58
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
+
58
71
/**
59
72
* Set the {@link ValueConverterRegistry converter registry} for path configured converters. This is short for adding
60
73
* a
@@ -78,7 +91,7 @@ public ValueConverterRegistry<?> getValueConverterRegistry() {
78
91
}
79
92
80
93
/**
81
- * Dis-/Enable caching . Enabled by default.
94
+ * Configure whether to use converter cache . Enabled by default.
82
95
*
83
96
* @param converterCacheEnabled set to {@literal true} to enable caching of {@link PropertyValueConverter converter}
84
97
* instances.
@@ -89,14 +102,14 @@ public void setConverterCacheEnabled(boolean converterCacheEnabled) {
89
102
90
103
@ Override
91
104
public boolean hasValueConverter (PersistentProperty <?> property ) {
92
- return this . converterFactory .getConverter (property ) != null ;
105
+ return obtainConverterFactory () .getConverter (property ) != null ;
93
106
}
94
107
95
108
@ Nullable
96
109
@ Override
97
110
public <DV , SV , C extends PersistentProperty <C >, D extends ValueConversionContext <C >> PropertyValueConverter <DV , SV , D > getValueConverter (
98
111
C property ) {
99
- return this . converterFactory .getConverter (property );
112
+ return obtainConverterFactory () .getConverter (property );
100
113
}
101
114
102
115
/**
@@ -125,7 +138,7 @@ public void init() {
125
138
}
126
139
127
140
@ Override
128
- public void afterPropertiesSet () throws Exception {
141
+ public void afterPropertiesSet () {
129
142
init ();
130
143
}
131
144
}
0 commit comments