private String getStringValue ( Object instance , Field field ) throws IllegalAccessException { Class < ? > fieldType = field . getType ( ) ; // Only support primitive type, boxed type, String and Enum Preconditions . checkArgument ( fieldType . isPrimitive ( ) || Primitives . isWrapperType ( fieldType ) || String . class . equals ( fieldType ) || fieldType . isEnum ( ) , "Unsupported property type %s of field %s in class %s." , fieldType . getName ( ) , field . getName ( ) , field . getDeclaringClass ( ) . getName ( ) ) ; if ( ! field . isAccessible ( ) ) { field . setAccessible ( true ) ; } Object value = field . get ( instance ) ; if ( value == null ) { return null ; } // Key name is "className.fieldName". return fieldType . isEnum ( ) ? ( ( Enum < ? > ) value ) . name ( ) : value . toString ( ) ; }
Gets the value of the field in the given instance as String . Currently only allows primitive types boxed types String and Enum .