I have two Objects of same type.I want to create a method which can merge the properties of two object and can return a single object.
For Example: Consider a class ABC having 4 fields
Class ABC{
String name;
String id;
String salary;
String status;
}
Suppose the first object is
ABC[name=ZEE,id=2,salary=null,status=1]
and the second object is
ABC[name=john,id=null,salary=12200,status=null]
I want to make a generic method which can merge these two objects and can give result output as:
ABC[name=ZEE,id=2,salary=12200,status=1]
The method Should take two parameters of Object type:
Object mergeObject(Object Obj1, Object Obj2){
}
Note: It will take the first object property if both the objects have non-null value for that property.