Why do you need a library in order to do that?
Given that you specify this is a domain object graph then why not define and implement relevant interfaces to allow your domain objects to be visited by different visitor implementations? One of the implementations could (as you specify) reset each ID to null
.
Example
First define the interfaces to be implemented by objects that can be visited or act as visitors.
public interface Visitable {
void visit(Visitor visitor);
}
public interface Visitor {
void visitDomainObjectA(DomainObjectA obj);
void visitDomainObjectB(DomainObjectB obj);
}
Now define two domain object classes, both of which can be visited.
public abstract class DomainObject implements Visitable {
private Object id;
public Object getId() { return this.id; }
public void setId(Object id) { this.id = id; }
}
public class DomainObjectA extends DomainObject {
public void visit(Visitor visitor) {
visitor.visitDomainObjectA(this);
}
}
public class DomainObjectB extends DomainObject {
public void visit(Visitor visitor) {
visitor.visitDomainObjectB(this);
}
}
Now define a concrete Visitor implementation that does something useful:
public class MyVisitor implements Visitor {
public void visitDomainObjectA(DomainObjectA doa) {
doa.setId(null);
}
public void visitDomainObjectB(DomainObjectB dob) {
doa.setId(UUID.randomUUID());
}
}