PLAT-6226 Changed to use Objects and cast according to instanceof to handle encoding problems.