public static Matcher < JsonElement > areItemsValid ( final Validator validator ) { return new TypeSafeDiagnosingMatcher < JsonElement > ( ) { @ Override protected boolean matchesSafely ( JsonElement item , Description mismatchDescription ) { //we do not care for the properties if parent item is not JsonArray if ( ! item . isJsonArray ( ) ) return true ; for ( int i = 0 ; i < item . asJsonArray ( ) . length ( ) ; i ++ ) { StringBuilder sb = new StringBuilder ( ) ; if ( ! validator . validate ( item . asJsonArray ( ) . opt ( i ) , sb ) ) { mismatchDescription . appendText ( "item at pos: " + i + ", does not validate by validator " + validator . getTitle ( ) ) . appendText ( "\nDetails: " ) . appendText ( sb . toString ( ) ) ; return false ; } } return true ; } @ Override public void describeTo ( Description description ) { description . appendText ( "are array items valid" ) ; } } ; }
== > ARRAY == >