Convert a JSON-serializable representation back to a field.
779776
def field_from_json(self, key_and_type, json_value):
        """"""
        assert ':' in key_and_type
        key, type_code = key_and_type.split(':', 1)
        from_json = self.field_function(type_code, 'from_json')
        value = from_json(json_value)
        return key, value
1081582
def serialised( self ):
        """"""
        klass = self.__class__
        return ((klass.__module__, klass.__name__), tuple( (name, field.serialise( self._field_data[name], parent=self ) ) for name, field in klass._fields.items()))
1354140
def fromJSON(value):
        
        j = json.loads(value)
        v = GPRecordSet()
        if "defaultValue" in j:
            v.value = j['defaultValue']
        else:
            v.value = j['value']
        if 'paramName' in j:
            v.paramName = j['paramName']
        elif 'name' in j:
            v.paramName = j['name']
        return v
561242
def conv_to_json(obj, fields=None):
        
        if fields is None:
            return json_encode(OrderedDict(((x, obj[x]) for x in obj if not x.startswith('_')))) + '\n'

        result = json_encode(OrderedDict([(x, obj[x]) for x in fields if x in obj])) + '\n'

        return result
936288
def from_dict(cls: typing.Type[T], dikt) -> T:
        """"""
        return util.deserialize_model(dikt, cls)
924243
def for_json(self):
        """"""

        if self.multiselect:
            return super(MultiSelectField, self).for_json()

        value = self.get_python()
        if hasattr(value, 'for_json'):
            return value.for_json()

        return value
996574
def _deserialize(self, value, attr, data):
        """"""
        if value:
            value = self._format_phone_number(value, attr)

        return super(PhoneNumberField, self)._deserialize(value, attr, data)
57433
def _dictify(field, value):
    
    if value is None:
        return None
    elif field.type_:
        return value.to_dict()
    return field.dict_value(value)
1186090
def fromJSON(jsonValue):
        """"""
        jd = json.loads(jsonValue)
        features = []
        if 'fields' in jd:
            fields = jd['fields']
        else:
            fields = {'fields':[]}
        if 'features' in jd:
            for feat in jd['features']:
                wkid = None
                spatialReference =None
                if 'spatialReference' in jd:
                    spatialReference = jd['spatialReference']
                    if 'wkid' in jd['spatialReference']:
                        wkid = jd['spatialReference']['wkid']
                    elif 'latestWkid' in jd['spatialReference']: # kept for compatibility
                        wkid = jd['spatialReference']['latestWkid']
                features.append(Feature(json_string=feat, wkid=wkid, spatialReference=spatialReference))
        return FeatureSet(fields,
                          features,
                          hasZ=jd['hasZ'] if 'hasZ' in jd else False,
                          hasM=jd['hasM'] if 'hasM' in jd else False,
                          geometryType=jd['geometryType'] if 'geometryType' in jd else None,
                          objectIdFieldName=jd['objectIdFieldName'] if 'objectIdFieldName' in jd else None,
                          globalIdFieldName=jd['globalIdFieldName'] if 'globalIdFieldName' in jd else None,
                          displayFieldName=jd['displayFieldName'] if 'displayFieldName' in jd else None,
                          spatialReference=jd['spatialReference'] if 'spatialReference' in jd else None)
1212451
def serialize(self):
        """"""
        # Serialize fields to a dict
        data = {}
        for field_name in self:
            value = self._values.get(field_name)
            field = self.fields.get(field_name)
            if value is not None:
                if field.all:
                    value = [field.serialize(v) for v in value]
                else:
                    value = field.serialize(value)
            # Skip empty fields unless field.null
            if not field.null and ((field.all and value == []) or (not field.all and value in {None, ''})):
                continue
            data[field.name] = value
        return data
643169
def to_representation(self, instance):
        """"""
        serializer = self.serializer
        model = serializer.get_model()
        source = self.source

        if not self.kwargs['many'] and serializer.id_only():
            # attempt to optimize by reading the related ID directly
            # from the current instance rather than from the related object
            source_id = '%s_id' % source
            # try the faster way first:
            if hasattr(instance, source_id):
                return getattr(instance, source_id)
            elif model is not None:
                # this is probably a one-to-one field, or a reverse related
                # lookup, so let's look it up the slow way and let the
                # serializer handle the id dereferencing
                try:
                    instance = getattr(instance, source)
                except model.DoesNotExist:
                    instance = None

        # dereference ephemeral objects
        if model is None:
            instance = getattr(instance, source)

        if instance is None:
            return None

        return serializer.to_representation(instance)
616039
def serialize(value, field):
    
    assert isinstance(field, forms.Field)
    if isinstance(field, forms.ModelMultipleChoiceField):
        return json.dumps([v.pk for v in value])
    # todo: remove
    if isinstance(value, models.Model):
        return value.pk
    return value
911025
def from_json(cls, obj):
        
        if len(obj) == 2:
            (field, operator) = obj
            return cls(field, operator)
        if len(obj) > 2:
            (field, operator, value) = obj
            return cls(field, operator, value)
655605
def fields_to_dict(obj, skip_fields=None):
    
    data = {}
    obj = api.get_object(obj)
    for field_name, field in api.get_fields(obj).items():
        if skip_fields and field_name in skip_fields:
            continue
        if field.type == "computed":
            continue
        data[field_name] = field.get(obj)
    return data
668970
def serialize(self, value, primitive=False):
        """"""
        if hasattr(value, 'serialize'):
            # i.e. value is a nested model
            return value.serialize(primitive=primitive)
        else:
            return value
1328387
def to_json(self, *args, **kwargs):
        
        return json.dumps(self.serialized, *args, **kwargs)
22868
def field_pk_from_json(self, data):
        """"""
        model = get_model(data['app'], data['model'])
        return PkOnlyModel(self, model, data['pk'])