implement castToDoc