本文整理汇总了Java中org.springframework.beans.BeanWrapper.getPropertyTypeDescriptor方法的典型用法代码示例。如果您正苦于以下问题:Java BeanWrapper.getPropertyTypeDescriptor方法的具体用法?Java BeanWrapper.getPropertyTypeDescriptor怎么用?Java BeanWrapper.getPropertyTypeDescriptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.beans.BeanWrapper
的用法示例。
在下文中一共展示了BeanWrapper.getPropertyTypeDescriptor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateObject
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
private void generateObject(String prefix, Object target) {
BeanWrapper beanWrapper = new BeanWrapperImpl(target);
PropertyDescriptor[] descriptors = beanWrapper.getPropertyDescriptors();
for (PropertyDescriptor descriptor : descriptors) {
if (descriptor.getWriteMethod() == null) {
continue;
}
String name = descriptor.getName();
Class<?> type = descriptor.getPropertyType();
Method readMethod = descriptor.getReadMethod();
TypeDescriptor typeDescriptor = beanWrapper.getPropertyTypeDescriptor(name);
Required required = typeDescriptor.getAnnotation(Required.class);
Object value = getValue(type, prefix, name, readMethod);
if (value != null) {
beanWrapper.setPropertyValue(name, value);
} else if (required != null) {
throw new RuntimeException(String.format("property [%s]'s value can't be null!please check your config!", name));
}
}
}
示例2: convert
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
private static Map<String, Object> convert(Object value, ConversionService conversionService) {
BeanWrapper bean = new BeanWrapperImpl(value);
PropertyDescriptor[] properties = bean.getPropertyDescriptors();
Map<String, Object> convertedValue = new HashMap<>(properties.length);
for (int i = 0; i < properties.length; i++) {
String name = properties[i].getName();
Object propertyValue = bean.getPropertyValue(name);
if (propertyValue != null
&& conversionService.canConvert(propertyValue.getClass(), String.class)) {
TypeDescriptor source = bean.getPropertyTypeDescriptor(name);
String convertedPropertyValue =
(String) conversionService.convert(propertyValue, source, TYPE_STRING);
convertedValue.put(name, convertedPropertyValue);
}
}
return convertedValue;
}
示例3: convertProperty
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
private static Object convertProperty(BeanWrapper parentBean, String property,
ConversionService conversionService, Map<String, Object> parentValue) {
TypeDescriptor source = parentBean.getPropertyTypeDescriptor(property);
Object propertyValue = parentBean.getPropertyValue(property);
int dotIndex = property.indexOf('.');
if (dotIndex > 0) {
String baseProperty = property.substring(0, dotIndex);
String childProperty = property.substring(dotIndex + 1);
Map<String, Object> childValue = getChildValue(parentValue, baseProperty, childProperty);
BeanWrapper childBean = new BeanWrapperImpl(parentBean.getPropertyValue(baseProperty));
Object convertedProperty =
convertProperty(childBean, childProperty, conversionService, childValue);
childValue.put(childProperty, convertedProperty);
return childValue;
} else {
String convertedPropertyValue =
(String) conversionService.convert(propertyValue, source, TYPE_STRING);
return convertedPropertyValue;
}
}
示例4: extendMapIfNecessary
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
private void extendMapIfNecessary(BeanWrapper wrapper, BeanPath path, int index) {
String name = path.prefix(index);
TypeDescriptor parent = wrapper.getPropertyTypeDescriptor(name);
if (parent == null) {
return;
}
TypeDescriptor descriptor = parent.getMapValueTypeDescriptor();
if (descriptor == null) {
descriptor = TypeDescriptor.valueOf(Object.class);
}
if (!descriptor.isMap() && !descriptor.isCollection()
&& !descriptor.getType().equals(Object.class)) {
return;
}
String extensionName = path.prefix(index + 1);
if (wrapper.isReadableProperty(extensionName)) {
Object currentValue = wrapper.getPropertyValue(extensionName);
if ((descriptor.isCollection() && currentValue instanceof Collection)
|| (!descriptor.isCollection() && currentValue instanceof Map)) {
return;
}
}
Object extend = new LinkedHashMap<String, Object>();
if (descriptor.isCollection()) {
extend = new ArrayList<Object>();
}
if (descriptor.getType().equals(Object.class) && path.isLastNode(index)) {
extend = BLANK;
}
wrapper.setPropertyValue(extensionName, extend);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:32,代码来源:RelaxedDataBinder.java
示例5: getTypeDescriptor
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
* Obtains the descriptor of the filtered field
*
* @param fieldName
* @param entityType
* @return
*/
public static <T> TypeDescriptor getTypeDescriptor(String fieldName,
Class<T> entityType) {
String fieldNameToFindType = fieldName;
BeanWrapper beanWrapper = getBeanWrapper(entityType);
TypeDescriptor fieldDescriptor = null;
Class<?> propType = null;
// Find recursive the las beanWrapper
if (fieldName.contains(SEPARATOR_FIELDS)) {
String[] fieldNameSplitted = StringUtils.split(fieldName,
SEPARATOR_FIELDS);
for (int i = 0; i < fieldNameSplitted.length - 1; i++) {
propType = beanWrapper.getPropertyType(fieldNameSplitted[i]);
if (propType == null) {
throw new IllegalArgumentException(String.format(
"Property %s not found in %s (request %s.%s)",
fieldNameSplitted[i],
beanWrapper.getWrappedClass(), entityType,
fieldName));
}
beanWrapper = getBeanWrapper(propType);
}
fieldNameToFindType = fieldNameSplitted[fieldNameSplitted.length - 1];
}
fieldDescriptor = beanWrapper
.getPropertyTypeDescriptor(fieldNameToFindType);
return fieldDescriptor;
}
示例6: getTypeDescriptor
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public <T> TypeDescriptor getTypeDescriptor(String fieldName,
Class<T> entityType) {
String fieldNameToFindType = fieldName;
BeanWrapper beanWrapper = getBeanWrapper(entityType);
TypeDescriptor fieldDescriptor = null;
Class<?> propType = null;
// Find recursive the las beanWrapper
if (fieldName.contains(SEPARATOR_FIELDS)) {
String[] fieldNameSplitted = StringUtils.split(fieldName,
SEPARATOR_FIELDS);
for (int i = 0; i < fieldNameSplitted.length - 1; i++) {
propType = beanWrapper.getPropertyType(fieldNameSplitted[i]);
if (propType == null) {
throw new IllegalArgumentException(String.format(
"Property %s not found in %s (request %s.%s)",
fieldNameSplitted[i],
beanWrapper.getWrappedClass(), entityType,
fieldName));
}
beanWrapper = getBeanWrapper(propType);
}
fieldNameToFindType = fieldNameSplitted[fieldNameSplitted.length - 1];
}
fieldDescriptor = beanWrapper
.getPropertyTypeDescriptor(fieldNameToFindType);
return fieldDescriptor;
}