refactor the OptionalValidator and ObjectValidator