org.apache.commons.beanutils.SuppressPropertiesBeanIntrospector Java Examples

The following examples show how to use org.apache.commons.beanutils.SuppressPropertiesBeanIntrospector. 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: ConfigurationBeanUtils.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
public static <T> void populate(T targetObject, Map<String, Object> properties) {
	if (properties == null) {
		return;
	}

	T target = getTargetObject(targetObject);

	try {
		BeanUtilsBean beanUtils = new BeanUtilsBean();
		beanUtils.getPropertyUtils().addBeanIntrospector(DefaultBeanIntrospector.INSTANCE);
		beanUtils.getPropertyUtils().addBeanIntrospector(new KebabCasePropertyBeanIntrospector());
		beanUtils.getPropertyUtils().addBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
		beanUtils.copyProperties(target, properties);
	}
	catch (IllegalAccessException | InvocationTargetException e) {
		throw new IllegalArgumentException("Failed to populate target of type " + targetObject.getClass()
			+ " with properties " + properties, e);
	}
}
 
Example #2
Source File: BeanUtil.java    From lutece-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * BeanUtil initialization, considering Lutèce availables locales and date format properties
 */
public static void init( )
{
    _mapBeanUtilsBeans = new HashMap<>( );

    for ( Locale locale : I18nService.getAdminAvailableLocales( ) )
    {
        BeanUtilsBean beanUtilsBean = new BeanUtilsBean( );
        beanUtilsBean.getPropertyUtils( ).addBeanIntrospector( SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS );

        DateConverter dateConverter = new DateConverter( null );
        dateConverter.setPattern( I18nService.getDateFormatShortPattern( locale ) );
        beanUtilsBean.getConvertUtils( ).register( dateConverter, Date.class );
        _mapBeanUtilsBeans.put( locale.getLanguage( ), beanUtilsBean );
    }
}
 
Example #3
Source File: XmlFactoryConfiguration.java    From velocity-tools with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Reads an XML document from an {@link URL}
 * and uses it to configure this {@link FactoryConfiguration}.</p>
 * 
 * @param url the URL to read from
 */
protected void readImpl(URL url) throws IOException
{
    // since beanutils 1.9.4, we need to relax access to the 'class' method
    BeanUtilsBean.getInstance().getPropertyUtils().removeBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);

    Digester digester = new Digester();
    digester.setNamespaceAware(true);
    digester.setXIncludeAware(true);
    digester.setValidating(false);
    digester.setUseContextClassLoader(true);
    digester.push(this);
    digester.addRuleSet(getRuleSet());
    try
    {
        digester.parse(url);
    }
    catch (SAXException saxe)
    {
        throw new RuntimeException("There was an error while parsing the InputStream", saxe);
    }
    finally
    {
        BeanUtilsBean.getInstance().getPropertyUtils().resetBeanIntrospectors();
    }
}
 
Example #4
Source File: ParameterBeanMapperUtils.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates an object of the specified type and populates properties of the object from the provided
 * parameters.
 *
 * @param parameters a {@link Map} of values to populate the object from
 * @param cls the {@link Class} representing the type of the object to instantiate and populate
 * @param <T> the type of the object to instantiate and populate
 * @return the instantiated and populated object
 */
public static <T> T mapParametersToBean(Map<String, Object> parameters, Class<T> cls) {
	try {
		T bean = cls.newInstance();

		BeanUtilsBean beanUtils = new BeanUtilsBean();
		beanUtils.getPropertyUtils().addBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);
		beanUtils.populate(bean, parameters);

		return bean;
	}
	catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
		throw new IllegalArgumentException("Error mapping parameters to class of type " + cls.getName(), e);
	}
}