BeanUtils / PropertyUtils reading nested "collection"

1.9k Views Asked by At

Searching through google, SO couldn't find me a solution, so here's my problem -

I have a class Employee with a nested collection addresses of type java.util.Set. The structure looks like below

class Employee {

   private Set<Address> addresses;   

}

class Address {

  private String street;   

}

I would like to use Apache's BeanUtils or PropertyUtils to read the street property of the first Address object within the Employee object if exists. If the addresses set is null or empty, I should get the value null from the API. Can anyone please help me with the BeanUtils way of doing that?

What I have tried? -

BeanUtils.getProperty(e, "addresses.street"); 
BeanUtils.getProperty(e, "addresses[0].street"); 
BeanUtils.getProperty(e, "addresses.get(0).street"); 
BeanUtils.getNestedProperty(e, "addresses.street"); 

None of them worked.

0

There are 0 best solutions below