@@ -440,6 +440,38 @@ public void testThatFilterIncludesObjectsWithSomeExcludedProperties() throws Exc
440
440
assertThat (((Map <String , Object >) filteredSource .get ("obj" )), hasKey ("f2" ));
441
441
}
442
442
443
+ @ Test
444
+ public void testThatFilterExcludesObjectWithWildcardPrefix () throws Exception {
445
+ XContentBuilder builder = XContentFactory .jsonBuilder ().startObject ()
446
+ .startObject ("obj" )
447
+ .field ("f1" , "v1" )
448
+ .endObject ()
449
+ .endObject ();
450
+
451
+ Tuple <XContentType , Map <String , Object >> mapTuple = XContentHelper .convertToMap (builder .bytes (), true );
452
+ Map <String , Object > filteredSource = XContentMapValues .filter (mapTuple .v2 (), Strings .EMPTY_ARRAY , new String []{"*.f1" });
453
+
454
+ assertThat (filteredSource .size (), equalTo (0 ));
455
+ }
456
+
457
+ @ Test
458
+ public void testThatFilterExcludesFieldsWithWildcardPrefix () throws Exception {
459
+ XContentBuilder builder = XContentFactory .jsonBuilder ().startObject ()
460
+ .startObject ("obj" )
461
+ .field ("f1" , "v1" )
462
+ .field ("f2" , "v2" )
463
+ .endObject ()
464
+ .endObject ();
465
+
466
+ Tuple <XContentType , Map <String , Object >> mapTuple = XContentHelper .convertToMap (builder .bytes (), true );
467
+ Map <String , Object > filteredSource = XContentMapValues .filter (mapTuple .v2 (), Strings .EMPTY_ARRAY , new String []{"*.f1" });
468
+
469
+ assertThat (filteredSource .size (), equalTo (1 ));
470
+ assertThat (filteredSource , hasKey ("obj" ));
471
+ assertThat (((Map ) filteredSource .get ("obj" )).size (), equalTo (1 ));
472
+ assertThat (((Map <String , Object >) filteredSource .get ("obj" )), hasKey ("f2" ));
473
+ }
474
+
443
475
@ Test
444
476
public void testThatFilterIncludesEmptyObjectWhenUsingIncludes () throws Exception {
445
477
XContentBuilder builder = XContentFactory .jsonBuilder ().startObject ()
@@ -528,6 +560,25 @@ public void testFilterExcludesWithNestedObjects() throws Exception {
528
560
assertThat (filteredSource .size (), equalTo (0 ));
529
561
}
530
562
563
+ @ Test
564
+ public void testFilterExcludesNestedObjectAndKeepsParent () throws Exception {
565
+ XContentBuilder builder = XContentFactory .jsonBuilder ().startObject ()
566
+ .startObject ("obj1" )
567
+ .field ("f1" , "v1" )
568
+ .startObject ("obj2" )
569
+ .endObject ()
570
+ .endObject ()
571
+ .endObject ();
572
+
573
+ Tuple <XContentType , Map <String , Object >> mapTuple = XContentHelper .convertToMap (builder .bytes (), true );
574
+ Map <String , Object > filteredSource = XContentMapValues .filter (mapTuple .v2 (), Strings .EMPTY_ARRAY , new String []{"*.obj2.*" });
575
+
576
+ assertThat (filteredSource .size (), equalTo (1 ));
577
+ assertThat (filteredSource , hasKey ("obj1" ));
578
+ assertThat (((Map ) filteredSource .get ("obj1" )).size (), equalTo (1 ));
579
+ assertThat (((Map <String , Object >) filteredSource .get ("obj1" )), hasKey ("f1" ));
580
+ }
581
+
531
582
@ Test
532
583
public void testFilterOmitsObjectWithNestedExcludedObjects () throws Exception {
533
584
XContentBuilder builder = XContentFactory .jsonBuilder ().startObject ()
0 commit comments