@@ -46,6 +46,7 @@ public class HalFormsConfiguration {
46
46
private final Map <Class <?>, String > patterns ;
47
47
private final Consumer <ObjectMapper > objectMapperCustomizer ;
48
48
private final HalFormsOptionsFactory options ;
49
+ private final HalFormsValueFactory values ;
49
50
private final List <MediaType > mediaTypes ;
50
51
51
52
/**
@@ -61,24 +62,26 @@ public HalFormsConfiguration() {
61
62
* @param halConfiguration must not be {@literal null}.
62
63
*/
63
64
public HalFormsConfiguration (HalConfiguration halConfiguration ) {
64
- this (halConfiguration , new HashMap <>(), new HalFormsOptionsFactory (), __ -> {},
65
+ this (halConfiguration , new HashMap <>(), new HalFormsOptionsFactory (), new HalFormsValueFactory (), __ -> {},
65
66
Collections .singletonList (MediaTypes .HAL_FORMS_JSON ));
66
67
}
67
68
68
69
private HalFormsConfiguration (HalConfiguration halConfiguration , Map <Class <?>, String > patterns ,
69
- HalFormsOptionsFactory options , @ Nullable Consumer <ObjectMapper > objectMapperCustomizer ,
70
+ HalFormsOptionsFactory options , HalFormsValueFactory values , @ Nullable Consumer <ObjectMapper > objectMapperCustomizer ,
70
71
List <MediaType > mediaTypes ) {
71
72
72
73
Assert .notNull (halConfiguration , "HalConfiguration must not be null!" );
73
74
Assert .notNull (patterns , "Patterns must not be null!" );
74
75
Assert .notNull (objectMapperCustomizer , "ObjectMapper customizer must not be null!" );
75
76
Assert .notNull (options , "HalFormsSuggests must not be null!" );
77
+ Assert .notNull (values , "HalFormsValueFactory must not be null!" );
76
78
Assert .notNull (mediaTypes , "Media types must not be null!" );
77
79
78
80
this .halConfiguration = halConfiguration ;
79
81
this .patterns = patterns ;
80
82
this .objectMapperCustomizer = objectMapperCustomizer ;
81
83
this .options = options ;
84
+ this .values = values ;
82
85
this .mediaTypes = new ArrayList <>(mediaTypes );
83
86
}
84
87
@@ -97,7 +100,7 @@ public HalFormsConfiguration withPattern(Class<?> type, String pattern) {
97
100
Map <Class <?>, String > newPatterns = new HashMap <>(patterns );
98
101
newPatterns .put (type , pattern );
99
102
100
- return new HalFormsConfiguration (halConfiguration , newPatterns , options , objectMapperCustomizer , mediaTypes );
103
+ return new HalFormsConfiguration (halConfiguration , newPatterns , options , values , objectMapperCustomizer , mediaTypes );
101
104
}
102
105
103
106
/**
@@ -113,7 +116,7 @@ public HalFormsConfiguration withObjectMapperCustomizer(Consumer<ObjectMapper> o
113
116
114
117
return this .objectMapperCustomizer == objectMapperCustomizer //
115
118
? this //
116
- : new HalFormsConfiguration (halConfiguration , patterns , options , objectMapperCustomizer , mediaTypes );
119
+ : new HalFormsConfiguration (halConfiguration , patterns , options , values , objectMapperCustomizer , mediaTypes );
117
120
}
118
121
119
122
/**
@@ -136,7 +139,7 @@ public HalFormsConfiguration withMediaType(MediaType mediaType) {
136
139
List <MediaType > newMediaTypes = new ArrayList <>(mediaTypes );
137
140
newMediaTypes .add (mediaTypes .size () - 1 , mediaType );
138
141
139
- return new HalFormsConfiguration (halConfiguration , patterns , options , objectMapperCustomizer , newMediaTypes );
142
+ return new HalFormsConfiguration (halConfiguration , patterns , options , values , objectMapperCustomizer , newMediaTypes );
140
143
}
141
144
142
145
/**
@@ -167,7 +170,14 @@ public HalFormsConfiguration customize(ObjectMapper mapper) {
167
170
public <T > HalFormsConfiguration withOptions (Class <T > type , String property ,
168
171
Function <PropertyMetadata , HalFormsOptions > creator ) {
169
172
170
- return new HalFormsConfiguration (halConfiguration , patterns , options .withOptions (type , property , creator ),
173
+ return new HalFormsConfiguration (halConfiguration , patterns , options .withOptions (type , property , creator ), values ,
174
+ objectMapperCustomizer , mediaTypes );
175
+ }
176
+
177
+ public <T > HalFormsConfiguration withValues (Class <T > type , String property ,
178
+ Function <PropertyMetadata , String > creator ) {
179
+
180
+ return new HalFormsConfiguration (halConfiguration , patterns , options , values .withValues (type , property , creator ),
171
181
objectMapperCustomizer , mediaTypes );
172
182
}
173
183
@@ -189,6 +199,15 @@ HalFormsOptionsFactory getOptionsFactory() {
189
199
return options ;
190
200
}
191
201
202
+ /**
203
+ * Returns the {@link HalFormsValueFactory} to look up value from payload and property metadata.
204
+ *
205
+ * @return will never be {@literal null}.
206
+ */
207
+ HalFormsValueFactory getValuesFactory () {
208
+ return values ;
209
+ }
210
+
192
211
/**
193
212
* Returns the regular expression pattern that is registered for the given type.
194
213
*
0 commit comments