You can either handle this through inheritance, or containment.
You can have Person
and DataExporterPerson
extend something like AbstractPerson
. However, since you have not already done so, then it is probably inappropriate to do inheritance.
I think it was Effective C++ that talked about how containment is better than inheritance. IIRC the reason stated is that containment is more loosely coupled than inheritance.
Here you would have a object that contains both Person
and DataExporterPerson
. Your method would populate one of those for this union type object, and by seeing which one is null you would know which one you actually have.
public class DBPersonUnion {
private Person person = null;
private DataExporterPerson dataExporterPerson = null;
//getters and setters.
}