Java Code Examples for org.springframework.beans.BeanUtils#findPropertyType()

The following examples show how to use org.springframework.beans.BeanUtils#findPropertyType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuerydslUtils.java    From gvnix with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Obtains the class type of the property named as {@code fieldName} of the
 * entity.
 * 
 * @param fieldName the field name.
 * @param entity the entity with a property named as {@code fieldName}
 * @return the class type
 */
public static <T> Class<?> getFieldType1(String fieldName,
        PathBuilder<T> entity) {
    Class<?> entityType = entity.getType();
    String fieldNameToFindType = fieldName;

    // Makes the array of classes to find fieldName agains them
    Class<?>[] classArray = ArrayUtils.<Class<?>> toArray(entityType);
    if (fieldName.contains(SEPARATOR_FIELDS)) {
        String[] fieldNameSplitted = StringUtils.split(fieldName,
                SEPARATOR_FIELDS);
        for (int i = 0; i < fieldNameSplitted.length - 1; i++) {
            Class<?> fieldType = BeanUtils.findPropertyType(
                    fieldNameSplitted[i],
                    ArrayUtils.<Class<?>> toArray(entityType));
            classArray = ArrayUtils.add(classArray, fieldType);
            entityType = fieldType;
        }
        fieldNameToFindType = fieldNameSplitted[fieldNameSplitted.length - 1];
    }

    return BeanUtils.findPropertyType(fieldNameToFindType, classArray);
}
 
Example 2
Source File: QuerydslUtilsBeanImpl.java    From gvnix with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public <T> Class<?> getFieldType1(String fieldName, PathBuilder<T> entity) {
    Class<?> entityType = entity.getType();
    String fieldNameToFindType = fieldName;

    // Makes the array of classes to find fieldName agains them
    Class<?>[] classArray = ArrayUtils.<Class<?>> toArray(entityType);
    if (fieldName.contains(SEPARATOR_FIELDS)) {
        String[] fieldNameSplitted = StringUtils.split(fieldName,
                SEPARATOR_FIELDS);
        for (int i = 0; i < fieldNameSplitted.length - 1; i++) {
            Class<?> fieldType = BeanUtils.findPropertyType(
                    fieldNameSplitted[i],
                    ArrayUtils.<Class<?>> toArray(entityType));
            classArray = ArrayUtils.add(classArray, fieldType);
            entityType = fieldType;
        }
        fieldNameToFindType = fieldNameSplitted[fieldNameSplitted.length - 1];
    }

    return BeanUtils.findPropertyType(fieldNameToFindType, classArray);
}
 
Example 3
Source File: IEnum.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public IEnum<?> deserialize(JsonParser parser,
		DeserializationContext context)
		throws IOException, JsonProcessingException {
	// 目标对象
	Object currentValue = parser.getCurrentValue();
	// 目标对象的字段
	String currentName = parser.currentName();
	// 枚举类型以及值类型
	Class<IEnum<?>> enumType = (Class<IEnum<?>>) BeanUtils
			.findPropertyType(
					currentName, currentValue.getClass());
	Class<?> valueType = TYPE_CACHE.get(enumType);
	if (valueType == null) {
		valueType = ReflectUtil.getActualClass(enumType, IEnum.class,
				"V");
		TYPE_CACHE.put(enumType, valueType);
	}
	// 获取值并转换
	Object value = parser.readValueAs(valueType);
	if (value != null) {
		for (IEnum<?> e : enumType.getEnumConstants()) {
			if (e.getValue().equals(value)) {
				return e;
			}
		}
	}
	return null;
}
 
Example 4
Source File: IEnum.java    From mPass with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public IEnum<?> deserialize(JsonParser parser,
		DeserializationContext context)
		throws IOException, JsonProcessingException {
	// 目标对象
	Object currentValue = parser.getCurrentValue();
	// 目标对象的字段
	String currentName = parser.currentName();
	// 枚举类型以及值类型
	Class<IEnum<?>> enumType = (Class<IEnum<?>>) BeanUtils
			.findPropertyType(
					currentName, currentValue.getClass());
	Class<?> valueType = TYPE_CACHE.get(enumType);
	if (valueType == null) {
		valueType = ReflectUtil.getActualClass(enumType, IEnum.class,
				"V");
		TYPE_CACHE.put(enumType, valueType);
	}
	// 获取值并转换
	Object value = parser.readValueAs(valueType);
	if (value != null) {
		for (IEnum<?> e : enumType.getEnumConstants()) {
			if (e.getValue().equals(value)) {
				return e;
			}
		}
	}
	return null;
}