Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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: 24193

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!