public static String toStringSecure ( Annotation ann ) { Class < ? > annType = ann . annotationType ( ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( ' ' ) . append ( annType . getName ( ) ) . append ( ' ' ) ; boolean any = false ; for ( Method m : annType . getMethods ( ) ) { Object defaultValue = m . getDefaultValue ( ) ; if ( defaultValue != null ) { String name = m . getName ( ) ; Object value ; try { value = m . invoke ( ann ) ; if ( name . equals ( "password" ) && ! defaultValue . equals ( value ) ) { value = "********" ; } else if ( value instanceof Object [ ] ) { value = Arrays . toString ( ( Object [ ] ) value ) ; } else { value = String . valueOf ( value ) ; } } catch ( Throwable t ) { value = "<" + t + ">" ; } if ( any ) { sb . append ( ", " ) ; } else { any = true ; } sb . append ( name ) . append ( ' ' ) . append ( value ) ; } } return sb . append ( ' ' ) . toString ( ) ; }
Convert an annotation to a string but mask members named password .