import json


def deserialize(raw_data, cls):
  """
  Deserializes raw JSON data into an instance of cls.

  The data is deserialized, serialized again using the class's to_json_dict()
  implementation, and deserialized again, to make sure both from_json_dict()
  and to_json_dict() are working.
  """
  instance = cls.from_json_dict(json.loads(raw_data), None)
  return cls.from_json_dict(instance.to_json_dict(preserve_ro=True), None)