def generate_deserializers(self, data_type, api):
    deserializers = list()
    function_name = get_function_name('deserialize', data_type, 'json', api)
    sm = StaticMethod(function_name)
    sm.arguments.append(MethodArgument('obj'))
    sm.add_line('if obj is None:')
    sm.indent()
    sm.add_line('return None')
    sm.dedent()
    if isinstance(data_type, PrimitiveTypeRef):
      sm.add_line('if isinstance(obj, str):')
      sm.indent()
      sm.add_line('return json.loads(obj)')
      sm.dedent()
      sm.add_line('return obj')
      deserializers.append(sm)
    elif isinstance(data_type, ContainerTypeRef):
      sm.add_line('if isinstance(obj, list):')
      sm.indent()
      sm.add_line('data = obj')
      sm.dedent()
      sm.add_line('else:')
      sm.indent()
      sm.add_line('data = json.loads(obj)')
      sm.dedent()
      sm.add_line('container = []')
      sm.add_line('for item in data:')
      sm.indent()
      if isinstance(data_type.type, PrimitiveTypeRef):
        sm.add_line('container.append(item)')
      else:
        child_deserializers = self.generate_deserializers(data_type.type, api)
        deserializers.extend(child_deserializers)
        sm.add_line('container.append(' + child_deserializers[-1].name + '(item))')
      sm.dedent()
      if data_type.container == 'list':
        sm.add_line('return list(container)')
      else:
        sm.add_line('return set(container)')
      deserializers.append(sm)
    elif isinstance(data_type, NamedTypeDef):
      sm.add_line('if isinstance(obj, dict):')
      sm.indent()
      sm.add_line('data = obj')
      sm.dedent()
      sm.add_line('else:')
      sm.indent()
      sm.add_line('data = json.loads(obj)')
      sm.dedent()
      if PrimitiveTypeRef.PRIMITIVES in data_type.name:
        sm.add_line('return data')
      elif data_type.name == '_API_':
        sm.add_line('return API(data)')
      else:
        fields = data_type.fields
        constructor = 'result = ' + self.class_name_mappings[data_type.name] + '('
        i = 0
        for field in fields:
          if i > 0:
            constructor += ', '
          i += 1
          field_type = field.type.type
          param = self.get_class_parameter(data_type.name, field.name)
          if isinstance(field_type, PrimitiveTypeRef):
            sm.add_line(param + ' = data.get(\'' + field.name + '\')')
          elif isinstance(field_type, ContainerTypeRef) and \
               isinstance(field_type.type, PrimitiveTypeRef):
            sm.add_line(param + ' = data.get(\'' + field.name + '\')')
          elif isinstance(field_type, TypeDef):
            named_type = NamedTypeDef(name=data_type.name + '_' + field.name,
              fields=field_type.fields)
            child_deserializers = self.generate_deserializers(named_type, api)
            deserializers.extend(child_deserializers)
            sm.add_line(param + ' = ' + child_deserializers[-1].name + '(data.get(\'' + field.name + '\'))')
          else:
            child_deserializers = self.generate_deserializers(field_type, api)
            deserializers.extend(child_deserializers)
            sm.add_line(param + ' = ' + child_deserializers[-1].name + '(data.get(\'' + field.name + '\'))')
          constructor += param + '=' + param
        constructor += ')'
        sm.add_line(constructor)
        sm.add_line('return result')
      deserializers.append(sm)
    else:
      actual_type = api.get_type_by_name(data_type.get_reference_name())
      deserializers.extend(self.generate_deserializers(actual_type, api))
    return deserializers
dataset/ETHPy150Open hiranya911/rest-coder/python-lib/serializers.py/JSONSerializer.generate_deserializers/swapped operands of `in`