Groovy : fetching values of nested objects using xpath kind

186 Views Asked by At

I have POJO with nested objects which i need to translate to a simple object with out nesting for example i have a Person and Address as below

public class Person {
     private String firstName;
     private String lastName;
     private Address address;
}  

public class Address {
    private String lineOne;
    private String lineTwo;
}

I need to translate Person to PersonFlat which looks like

public class PersonFlat {
     private String firstName;
     private String lastName;
     private String Address_lineOne;
     private String Address_lineTwo;
}  

is there any way where i can do xpath kind of extraction on the Person instance to get the Address.lineOne and Address.lineTwo using groovy metaClass ?

0

There are 0 best solutions below