[CDAP-505] Added type check before casting