jeudi 17 janvier 2019

How to convert POJO values to object array

I have pojo class as;

public class Person {
    private int id;
    private String name;
    private String address;
    private int salary;
    // getter and setter
}

I want to convert value of this pojo class object to object array as;

Object[] perObjArray = new Object[4];
empObjArray[0] = personObjcet.getId();
empObjArray[1] = personObjcet.getName();
empObjArray[2] = personObjcet.getAddress();
empObjArray[3] = personObjcet.getSalary();

Like this scenario, i have other pojo classes. I want to create generic method where i can pass pojo object and it will return object array of those values.

I know we can use reflection, but not sure how ? Please help..





Aucun commentaire:

Enregistrer un commentaire