@@ -212,7 +212,7 @@ private Map<String, Object> asMap(Object object) {
212
212
213
213
private boolean process (Map <String , Object > map , MatchCallback callback ) {
214
214
Properties properties = new Properties ();
215
- assignProperties ( properties , map , null );
215
+ properties . putAll ( getFlattenedMap ( map ) );
216
216
217
217
if (this .documentMatchers .isEmpty ()) {
218
218
if (this .logger .isDebugEnabled ()) {
@@ -247,8 +247,23 @@ private boolean process(Map<String, Object> map, MatchCallback callback) {
247
247
return false ;
248
248
}
249
249
250
- private void assignProperties (Properties properties , Map <String , Object > input , String path ) {
251
- for (Entry <String , Object > entry : input .entrySet ()) {
250
+ /**
251
+ * Return a flattened version of the given map, recursively following any nested Map
252
+ * or Collection values. Entries from the resulting map retain the same order as the
253
+ * source. When called with the Map from a {@link MatchCallback} the result will
254
+ * contain the same values as the {@link MatchCallback} Properties.
255
+ * @param source the source map
256
+ * @return a flattened map
257
+ * @since 4.2.3
258
+ */
259
+ protected final Map <String , Object > getFlattenedMap (Map <String , Object > source ) {
260
+ Map <String , Object > result = new LinkedHashMap <String , Object >();
261
+ buildFlattenedMap (result , source , null );
262
+ return result ;
263
+ }
264
+
265
+ private void buildFlattenedMap (Map <String , Object > result , Map <String , Object > source , String path ) {
266
+ for (Entry <String , Object > entry : source .entrySet ()) {
252
267
String key = entry .getKey ();
253
268
if (StringUtils .hasText (path )) {
254
269
if (key .startsWith ("[" )) {
@@ -260,26 +275,26 @@ private void assignProperties(Properties properties, Map<String, Object> input,
260
275
}
261
276
Object value = entry .getValue ();
262
277
if (value instanceof String ) {
263
- properties .put (key , value );
278
+ result .put (key , value );
264
279
}
265
280
else if (value instanceof Map ) {
266
281
// Need a compound key
267
282
@ SuppressWarnings ("unchecked" )
268
283
Map <String , Object > map = (Map <String , Object >) value ;
269
- assignProperties ( properties , map , key );
284
+ buildFlattenedMap ( result , map , key );
270
285
}
271
286
else if (value instanceof Collection ) {
272
287
// Need a compound key
273
288
@ SuppressWarnings ("unchecked" )
274
289
Collection <Object > collection = (Collection <Object >) value ;
275
290
int count = 0 ;
276
291
for (Object object : collection ) {
277
- assignProperties ( properties ,
292
+ buildFlattenedMap ( result ,
278
293
Collections .singletonMap ("[" + (count ++) + "]" , object ), key );
279
294
}
280
295
}
281
296
else {
282
- properties .put (key , value == null ? "" : value );
297
+ result .put (key , value == null ? "" : value );
283
298
}
284
299
}
285
300
}
0 commit comments