private JsonMBean extractJsonMBeanAnnotation ( Object object ) { // Try directly Class < ? > clazz = object . getClass ( ) ; JsonMBean anno = clazz . getAnnotation ( JsonMBean . class ) ; if ( anno == null && ModelMBean . class . isAssignableFrom ( object . getClass ( ) ) ) { // For ModelMBean we try some heuristic to get to the managed resource // This works for all subclasses of RequiredModelMBean as provided by the JDK // but maybe for other ModelMBean classes as well Boolean isAccessible = null ; Field field = null ; try { field = findField ( clazz , "managedResource" ) ; if ( field != null ) { isAccessible = field . isAccessible ( ) ; field . setAccessible ( true ) ; Object managedResource = field . get ( object ) ; anno = managedResource . getClass ( ) . getAnnotation ( JsonMBean . class ) ; } } catch ( IllegalAccessException e ) { // Ignored silently, but we tried it at least } finally { if ( isAccessible != null ) { field . setAccessible ( isAccessible ) ; } } } return anno ; }
Lookup a JsonMBean annotation