Try to get the serializer class from view method.
        If view method don't have request serializer, fallback to serializer_class on view class
976609
def get_serializer_class(self, view, method_func):
        
        if hasattr(method_func, 'request_serializer'):
            return getattr(method_func, 'request_serializer')

        if hasattr(view, 'serializer_class'):
            return getattr(view, 'serializer_class')

        if hasattr(view, 'get_serializer_class'):
            return getattr(view, 'get_serializer_class')()

        return None
1312565
def get_object(self, view_name, view_args, view_kwargs):
        
        lookup_value = view_kwargs[self.lookup_url_kwarg]
        lookup_kwargs = {self.lookup_field: lookup_value}
        return self.get_queryset().get(**lookup_kwargs)
506110
def get_object(self, view_kwargs, qs=None):
        
        self.before_get_object(view_kwargs)

        id_field = getattr(self, 'id_field', inspect(self.model).primary_key[0].key)
        try:
            filter_field = getattr(self.model, id_field)
        except Exception:
            raise Exception("{} has no attribute {}".format(self.model.__name__, id_field))

        url_field = getattr(self, 'url_field', 'id')
        filter_value = view_kwargs[url_field]

        query = self.retrieve_object_query(view_kwargs, filter_field, filter_value)

        if qs is not None:
            query = self.eagerload_includes(query, qs)

        try:
            obj = query.one()
        except NoResultFound:
            obj = None

        self.after_get_object(obj, view_kwargs)

        return obj
570213
def get_validation_description(view, method):
    
    if method not in ('PUT', 'PATCH', 'POST') or not hasattr(view, 'get_serializer'):
        return ''

    serializer = view.get_serializer()
    description = ''
    if hasattr(serializer, 'validate') and serializer.validate.__doc__ is not None:
        description += formatting.dedent(smart_text(serializer.validate.__doc__))

    for field in serializer.fields.values():
        if not hasattr(serializer, 'validate_' + field.field_name):
            continue

        field_validation = getattr(serializer, 'validate_' + field.field_name)

        if field_validation.__doc__ is not None:
            docstring = formatting.dedent(smart_text(field_validation.__doc__)).replace('\n', '\n\t')
            field_description = '* %s\n * %s' % (field.field_name, docstring)
            description += '\n' + field_description if description else field_description

    return '### Validation:\n' + description if description else ''
950737
def get_serializer(self, *args, **kwargs):
        
        action = kwargs.pop('action', None)

        serializer_class = self.get_serializer_class(action)

        kwargs['context'] = self.get_serializer_context()
        return serializer_class(*args, **kwargs)
327810
def process_view(self, request, view_func, view_args, view_kwargs):
        

        # Purge data in view method cache
        # Python 3's keys() method returns an iterator, so force evaluation before iterating.
        view_keys = list(VIEW_METHOD_DATA.keys())
        for key in view_keys:
            del VIEW_METHOD_DATA[key]

        self.view_data = {}

        try:
            cbv = view_func.view_class
        except AttributeError:
            cbv = False

        if cbv:

            self.view_data['cbv'] = True
            klass = view_func.view_class
            self.view_data['bases'] = [base.__name__ for base in inspect.getmro(klass)]
            # Inject with drugz

            for member in inspect.getmembers(view_func.view_class):
                # Check that we are interested in capturing data for this method
                # and ensure that a decorated method is not decorated multiple times.
                if member[0] in VIEW_METHOD_WHITEIST and member[0] not in PATCHED_METHODS[klass]:
                    decorate_method(klass, member[0])
                    PATCHED_METHODS[klass].append(member[0])
983008
def get_serializer_fields(self, path, method, view):
        
        if method not in ('PUT', 'PATCH', 'POST'):
            return []

        if not hasattr(view, 'get_serializer'):
            return []

        serializer = view.get_serializer()
        if not isinstance(serializer, Serializer):
            return []

        fields = []
        for field in serializer.fields.values():
            if field.read_only or isinstance(field, HiddenField):
                continue

            required = field.required and method != 'PATCH'
            description = force_text(field.help_text) if field.help_text else ''
            field_type = get_field_type(field)
            description += '; ' + field_type if description else field_type
            field = coreapi.Field(
                name=field.field_name,
                location='form',
                required=required,
                description=description,
                schema=schemas.field_to_schema(field),
            )
            fields.append(field)

        return fields
1033412
def get_form_class(self):
        
        if self.form_class:
            form_class = self.form_class

        else:
            if self.model is not None:
                # If a model has been explicitly provided, use it
                model = self.model
            elif hasattr(self, 'object') and self.object is not None:
                # If this view is operating on a single object, use
                # the class of that object
                model = self.object.__class__
            else:
                # Try to get a queryset and extract the model class
                # from that
                model = self.get_queryset().model

            # run time parameters when building our form
            factory_kwargs = self.get_factory_kwargs()
            form_class = model_forms.modelform_factory(model, **factory_kwargs)

        return form_class
515724
def get_object(self, request, object_id, from_field=None):
        
        # from_field breaks in 1.7.8
        obj = super(VersionedAdmin, self).get_object(request,
                                                     object_id)
        # Only clone if update view as get_object() is also called for change,
        # delete, and history views
        if request.method == 'POST' and \
                obj and \
                obj.is_latest and \
                'will_not_clone' not in request.path and \
                'delete' not in request.path and \
                'restore' not in request.path:
            obj = obj.clone()

        return obj
278618
def get_serializer_class(self):
        
        klass = None

        lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
        if lookup_url_kwarg in self.kwargs:
            # Looks like this is a detail...
            klass = self.get_object().__class__
        elif "doctype" in self.request.REQUEST:
            base = self.model.get_base_class()
            doctypes = indexable_registry.families[base]
            try:
                klass = doctypes[self.request.REQUEST["doctype"]]
            except KeyError:
                raise Http404

        if hasattr(klass, "get_serializer_class"):
            return klass.get_serializer_class()

        # TODO: fix deprecation warning here -- `get_serializer_class` is going away soon!
        return super(ContentViewSet, self).get_serializer_class()
146676
def post_loader(*decorator_args, serializer):
    
    def wrapped(fn):
        @wraps(fn)
        def decorated(*args, **kwargs):
            return fn(*serializer.load(request.get_json()))
        return decorated

    if decorator_args and callable(decorator_args[0]):
        return wrapped(decorator_args[0])
    return wrapped
1035895
def _match_view(self, method, route_params):
        
        method = method.upper()
        route_params = frozenset(k for k, v in route_params.items() if v is not None)

        for view_name, info in self.methods_map[method].items():
            if info.matches(method, route_params):
                return getattr(self, view_name)
        else:
            return None
1322250
def get_url(self, obj, view_name, request, format):
        
        # Unsaved objects will not yet have a valid URL.
        if obj.pk is None:
            return None

        lookup_value = getattr(obj, self.lookup_field)
        lookup_kwargs = {
            self.lookup_field: lookup_value,
        }

        # Try to lookup parent attr
        parent_lookup_value = None
        for attr in self.parent_lookup_field.split("__"):
            if not hasattr(obj, attr):
                break
            parent_lookup_value = getattr(parent_lookup_value or obj, attr)
        if parent_lookup_value:
            lookup_kwargs.update({self.parent_lookup_field: parent_lookup_value})

        return self.reverse(view_name, kwargs=lookup_kwargs, request=request, format=format)
1104065
def _import_serializer_class(self, location):
        
        pieces = location.split(".")
        class_name = pieces.pop()

        if pieces[len(pieces) - 1] != "serializers":
            pieces.append("serializers")

        module = importlib.import_module(".".join(pieces))
        return getattr(module, class_name)
192526
private Serializer<?> getSerializerFromClass(Class<?> klass) {
        if(klass == Integer.class) {
            return Serializer.INTEGER;
        }
        else if(klass == Long.class) {
            return Serializer.LONG;
        }
        else if(klass == Boolean.class) {
            return Serializer.BOOLEAN;
        }
        else if(klass == String.class) {
            return Serializer.STRING;
        }
        return null; //Default POJO serializer
    }
754869
def get_object(self, queryset=None):
        
        try:
            pk = self.kwargs.get('pk', None)

            # allow serializer without service
            obj = self.service.get(pk)
            return obj
        except self.model.DoesNotExist:
            raise Http404()
133794
def get_facet_serializer_class(self):
        
        if self.facet_serializer_class is None:
            raise AttributeError(
                "%(cls)s should either include a `facet_serializer_class` attribute, "
                "or override %(cls)s.get_facet_serializer_class() method." %
                {"cls": self.__class__.__name__}
            )
        return self.facet_serializer_class