File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Java Bean retrieving all Non-Null Attributes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Bean retrieving all Non-Null Attributes" Watch "Java Bean retrieving all Non-Null Attributes" New topic

Java Bean retrieving all Non-Null Attributes

Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
Suppose I have a class

class People(){
String firstName;
String lastName;
int name;
public String getFirstName()
public void setFirstName(String firstName);

And i intend to obtain all the non Null attributes of an object that is an instance of this class

for instance

People people=new People();

Array tempMap=someutilityClass(people);

someutilityClass would return an array of attributes that are not null, Any pointers on how to accomplish this
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Use java.beans.Introspector to get a list of PropertyDescriptors, then check each property to see if it's null or not. Were you expecting something more?

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Java Bean retrieving all Non-Null Attributes
It's not a secret anymore!