added nil checks to mapper doc_to_entity()