public static Map < String , Object > getProperties ( Object obj ) { Map < String , Object > map = new HashMap < String , Object > ( ) ; Class < ? > objClass = obj . getClass ( ) ; // Get all fields for ( Field field : objClass . getFields ( ) ) { try { if ( matchField ( field , field . getName ( ) ) ) { String name = field . getName ( ) ; Object value = field . get ( obj ) ; map . put ( name , value ) ; } } catch ( Throwable t ) { // Ignore exception } } // Get all properties for ( Method method : objClass . getMethods ( ) ) { try { if ( method . getName ( ) . startsWith ( "get" ) && matchPropertyGetter ( method , method . getName ( ) ) ) { String name = method . getName ( ) . substring ( 3 ) ; name = name . substring ( 0 , 1 ) . toLowerCase ( ) + name . substring ( 1 ) ; Object value = method . invoke ( obj ) ; map . put ( name , value ) ; } } catch ( Throwable t ) { // Ignore exception } } return map ; }
Get values of all properties in specified object and returns them as a map .