Modified encodeAnonymousObject to also go through fields of class instance.