Java Code Examples for org.apache.commons.beanutils.SuppressPropertiesBeanIntrospector

The following examples show how to use org.apache.commons.beanutils.SuppressPropertiesBeanIntrospector. These examples are extracted from open source projects. 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
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 Project: lutece-core   Source File: BeanUtil.java    License: 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 Project: velocity-tools   Source File: XmlFactoryConfiguration.java    License: 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
/**
 * 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);
	}
}