public static boolean isVacantJson ( final Object obj ) { Collection values = null ; if ( obj instanceof Collection ) { if ( ( ( Collection ) obj ) . size ( ) == 0 ) { return true ; } values = ( Collection ) obj ; } if ( obj instanceof Map ) { if ( ( ( Map ) obj ) . size ( ) == 0 ) { return true ; } values = ( ( Map ) obj ) . values ( ) ; } int processedEmpty = 0 ; if ( values != null ) { for ( Object value : values ) { if ( ! isVacantJson ( value ) ) { return false ; } processedEmpty ++ ; } if ( processedEmpty == values . size ( ) ) { return true ; } } return false ; }
Vacant implies there are empty placeholders i . e . a vacant hotel Given a json document checks if it has any leaf values can handle deep nesting of lists and maps