Question: So I have an model serializer which consists of

```
class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ('id', 'name', 'description')

```

This is my ViewSet

```
class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer

```

This is my URLs.py file:

```
from django.conf.urls import include, url
from rest_framework import routers
import views

router = DefaultRouter()
router.register('user', views.UserViewSet)
urlpatterns = [
    url(r'^', include(router.urls)),
    url(r'^login/', include('rest_framework.urls', namespace='rest_framework'))
]

```

Using the serializer, I can make it print out the objects inside my database. If I have the object PK/ID, I want to be able to update the field `id` or `name` of the object. Is there a way I can do that with a patch/post request using the serializer? I'm new to this so I'd love it if someone can help me out with this.

I'm thinking of just doing a `POST` request, then have it do this:

```
user = User.objects.get(id=id)
user.name = "XXXXX"
user.save()

```

But I want to do this using the serializer, using a `PATCH` request.

Answer: 
`StringBuffer` does NOT override `equals()` method. So, it uses the implementation of `Object` class which checks for the reference equality (Checks if both the objects are the **same**).

In your case, both the objects are obviously not the same (though their contents are the same), hence it fails.

`String` on the other hand overrides the `equals()` method and returns `true` if the contents of both the Strings are the same.
assertEquals(exp, orig); is basically comparing the reference of the two objects. As you know that in memory both the objects are separately created with unique reference id and that's the reason test case is failing. 

See following code and its output: 

```
@Test
    public void equal()
    {
        TestClass obj1= new TestClass();
        TestClass obj2= new TestClass();
        Assert.assertEquals(obj1,obj2);
    }

```

Following is the output in which you can cleary see the expected and actual result which is a memory reference. 

```
java.lang.AssertionError: 
Expected :com.company.TestClass@6c20cbef
Actual   :com.company.TestClass@5d2cef5e

```

Now if I assign obj1 to obj2 then both object references point to the same object; see below example which will pass the test case. 

```
@Test
    public void equal()
    {
        TestClass obj1= new TestClass();
        TestClass obj2;
        obj2= obj1;
        Assert.assertEquals(obj1,obj2);
    }

```