Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7994895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:15:00+00:00 2026-06-04T14:15:00+00:00

I have a bean, is there a way to list bean’s all properties without

  • 0

I have a bean, is there a way to list bean’s all properties without list one by one?

Some beans overide the ToString() method which is handy. Howvere the beans which does not override this method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:15:02+00:00Added an answer on June 4, 2026 at 2:15 pm

    You can use reflection. Take declared fields from class, it they are private check if they have setters and getters (remember boolean getter is “isProperty”)

    Code can look like this:

    List<String> properties = new ArrayList<String>();
    Class<?> cl = MyBean.class;
    
    // check all declared fields
    for (Field field : cl.getDeclaredFields()) {
    
        // if field is private then look for setters/getters
        if (Modifier.isPrivate(field.getModifiers())) {
    
            // changing 1st letter to upper case
            String name = field.getName();
            String upperCaseName = name.substring(0, 1).toUpperCase()
                    + name.substring(1);
            // and have getter and setter
            try {
                String simpleType = field.getType().getSimpleName();
                //for boolean property methods should be isProperty and setProperty(propertyType)
                if (simpleType.equals("Boolean") || simpleType.equals("boolean")) {
                    if ((cl.getDeclaredMethod("is" + upperCaseName) != null)
                            && (cl.getDeclaredMethod("set" + upperCaseName,
                                    field.getType()) != null)) {
                        properties.add(name);
                    }
                } 
                //for not boolean property methods should be getProperty and setProperty(propertyType)
                else {
                    if ((cl.getDeclaredMethod("get" + upperCaseName) != null)
                            && (cl.getDeclaredMethod("set" + upperCaseName,
                                    field.getType()) != null)) {
                        properties.add(name);
                    }
                }
            } catch (NoSuchMethodException | SecurityException e) {
                // if there is no method nothing bad will happen
            }
        }
    }
    for (String property:properties)
        System.out.println(property);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to obtain Object array of Java Bean fields? I have
I have created a spring bean that contains a list of other beans, like
In Spring 2.0, is there a quick way to have a list of the
I have an action bean in my stripes application. The default handler/method will display
So I have bean named element that has a list of categories in and
I have a backing bean containing this object: List<Session> sessions; and a Session is
In Eclipse is there any way that given a class with a list of
In my application, I have an @ApplicationScoped CDI bean to store some information from
In my project I have all services designed as stateless session beans. During the
I have a situation, I have a session bean with list, this list I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.