Refactor BaseValidatorWriter

Refactored BaseValidatorWriter to determine its own supported type via
reflection.

Moved some casting utility code to CastUtil class.

Added tests for castings