public static Set < String > getPropertyNames ( final Class < ? > targetClass ) { HashSet < String > set = new HashSet <> ( ) ; Matcher matcher = GETTER_PATTERN . matcher ( "" ) ; for ( Method method : targetClass . getMethods ( ) ) { String name = method . getName ( ) ; if ( method . getParameterTypes ( ) . length == 0 && matcher . reset ( name ) . matches ( ) ) { name = name . replaceFirst ( "(get|is)" , "" ) ; try { if ( targetClass . getMethod ( "set" + name , method . getReturnType ( ) ) != null ) { name = Character . toLowerCase ( name . charAt ( 0 ) ) + name . substring ( 1 ) ; set . add ( name ) ; } } catch ( Exception e ) { // fall thru (continue) } } } return set ; }
Get the bean - style property names for the specified object .