Skip to content
This repository has been archived by the owner on Aug 8, 2020. It is now read-only.

Provides convenience methods for working with Java beans and reflection.

License

Notifications You must be signed in to change notification settings

codereligion/cherry-reflect

Repository files navigation

cherry-logo Reflect Maven Central Build Status SonarQube Coverage

This library is part of the cherry project, it provides convenience methods to do Java bean introspection. It's main functionality is to provide a very thin wrapper around the java.beans.Introspector, which can not handle generic classes to well in Java version 1.6.

For more details have a look at the wiki.

Requirements

Example code

package com.codereligion.example;

import com.codereligion.example.bean.User;
import com.codereligion.cherry.reflect.BeanIntrospections;
import com.codereligion.cherry.reflect.GenericTypeAwareBeanInfo;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.Set;

public class Example {

    public void example() throws IntrospectionException {
        // check if a class has a default constructor
        boolean hasDefaultConstructor = BeanIntrospections.hasDefaultConstructor(User.class);

        // get property descriptors, even for classes with generic members
        Set<PropertyDescriptor> writeables = BeanIntrospections.getWriteableProperties(User.class);
        Set<PropertyDescriptor> readables = BeanIntrospections.getReadableProperties(User.class);
        Set<PropertyDescriptor> writeableAndReables = BeanIntrospections.getWriteableAndReadableProperties(User.class);

        // decorate a BeanInfo so that it can handle generics
        BeanInfo beanInfo = GenericTypeAwareBeanInfo.of(Introspector.getBeanInfo(User.class));
    }
}

About

Provides convenience methods for working with Java beans and reflection.

Resources

License

Stars

Watchers

Forks

Packages

No packages published