Java Code Examples for org.springframework.beans.BeanWrapperImpl#getPropertyDescriptors()
The following examples show how to use
org.springframework.beans.BeanWrapperImpl#getPropertyDescriptors() .
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: BeanUtils.java From White-Jotter with MIT License | 6 votes |
/** * Gets null names set of property. * * @param source object data must not be null * @return null name set of property */ @NonNull private static Set<String> getNullPropertyNameSet(@NonNull Object source) { Assert.notNull(source, "source object must not be null"); BeanWrapperImpl beanWrapper = new BeanWrapperImpl(source); PropertyDescriptor[] propertyDescriptors = beanWrapper.getPropertyDescriptors(); Set<String> emptyNames = new HashSet<>(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String propertyName = propertyDescriptor.getName(); Object propertyValue = beanWrapper.getPropertyValue(propertyName); // if property value is equal to null, add it to empty name set if (propertyValue == null) { emptyNames.add(propertyName); } } return emptyNames; }
Example 2
Source File: BeanUtils.java From halo with GNU General Public License v3.0 | 6 votes |
/** * Gets null names set of property. * * @param source object data must not be null * @return null name set of property */ @NonNull private static Set<String> getNullPropertyNameSet(@NonNull Object source) { Assert.notNull(source, "source object must not be null"); BeanWrapperImpl beanWrapper = new BeanWrapperImpl(source); PropertyDescriptor[] propertyDescriptors = beanWrapper.getPropertyDescriptors(); Set<String> emptyNames = new HashSet<>(); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String propertyName = propertyDescriptor.getName(); Object propertyValue = beanWrapper.getPropertyValue(propertyName); // if property value is equal to null, add it to empty name set if (propertyValue == null) { emptyNames.add(propertyName); } } return emptyNames; }
Example 3
Source File: SolrClientUtils.java From dubbox with Apache License 2.0 | 6 votes |
/** * Solr property names do not match the getters/setters used for them. Check * on any write method, try to find the according property and set the value * for it. Will ignore all other, and nested properties * * @param source * @param target */ private static void copyProperties(SolrClient source, SolrClient target) { BeanWrapperImpl wrapperImpl = new BeanWrapperImpl(source); for (PropertyDescriptor pd : wrapperImpl.getPropertyDescriptors()) { Method writer = pd.getWriteMethod(); if (writer != null) { try { Field property = ReflectionUtils.findField(source.getClass(), pd.getName()); if (property != null) { ReflectionUtils.makeAccessible(property); Object o = ReflectionUtils.getField(property, source); if (o != null) { writer.invoke(target, o); } } } catch (Exception e) { logger.warn("Could not copy property value for: " + pd.getName(), e); } } } }
Example 4
Source File: ControllerUtils.java From wallride with Apache License 2.0 | 6 votes |
public static MultiValueMap<String, String> convertBeanForQueryParams(Object target, ConversionService conversionService) { BeanWrapperImpl beanWrapper = new BeanWrapperImpl(target); beanWrapper.setConversionService(conversionService); MultiValueMap<String, String> queryParams = new LinkedMultiValueMap(); for (PropertyDescriptor pd : beanWrapper.getPropertyDescriptors()) { if (beanWrapper.isWritableProperty(pd.getName())) { Object pv = beanWrapper.getPropertyValue(pd.getName()); if (pv != null) { if (pv instanceof Collection) { if (!CollectionUtils.isEmpty((Collection) pv)) { for (Object element : (Collection) pv) { queryParams.set(pd.getName(), convertPropertyValueForString(target, pd, element)); } } } else { queryParams.set(pd.getName(), convertPropertyValueForString(target, pd, pv)); } } } } return queryParams; }
Example 5
Source File: CommandLineHelpGenerator.java From initializr with Apache License 2.0 | 5 votes |
protected Map<String, Object> buildParametersDescription(InitializrMetadata metadata) { Map<String, Object> result = new LinkedHashMap<>(); BeanWrapperImpl wrapper = new BeanWrapperImpl(metadata); for (PropertyDescriptor descriptor : wrapper.getPropertyDescriptors()) { Object value = wrapper.getPropertyValue(descriptor.getName()); BeanWrapperImpl nested = new BeanWrapperImpl(value); if (nested.isReadableProperty("description") && nested.isReadableProperty("id")) { result.put((String) nested.getPropertyValue("id"), nested.getPropertyValue("description")); } } result.put("applicationName", "application name"); result.put("baseDir", "base directory to create in the archive"); return result; }