Example usage for org.springframework.data.repository.util ClassUtils hasProperty

List of usage examples for org.springframework.data.repository.util ClassUtils hasProperty

Introduction

In this page you can find the example usage for org.springframework.data.repository.util ClassUtils hasProperty.

Prototype

public static boolean hasProperty(Class<?> type, String property) 

Source Link

Document

Returns whether the given class contains a property with the given name.

Usage

From source file:com.frank.search.solr.core.ResultHelper.java

private static Object getMappedId(Object o) {
    if (ClassUtils.hasProperty(o.getClass(), "id")) {
        try {/*from  w  ww.java2 s .c  o  m*/
            return FieldUtils.readDeclaredField(o, "id", true);
        } catch (IllegalAccessException e) {
            throw new MappingException("Id property could not be accessed!", e);
        }
    }

    for (java.lang.reflect.Field field : o.getClass().getDeclaredFields()) {
        Annotation annotation = AnnotationUtils.getAnnotation(field, Id.class);
        if (annotation != null) {
            try {
                return FieldUtils.readField(field, o, true);
            } catch (IllegalArgumentException e) {
                throw new MappingException("Id property could not be accessed!", e);
            } catch (IllegalAccessException e) {
                throw new MappingException("Id property could not be accessed!", e);
            }
        }
    }
    throw new MappingException("Id property could not be found!");
}