title: Django REST Framework - Serializing optional fields
body: <p>I have an object that has optional fields. I have defined my serializer this way:</p>
  
  <pre><code>class ProductSerializer(serializers.Serializer):
      code = serializers.Field(source="Code")
      classification = serializers.CharField(source="Classification", required=False)
  </code></pre>
  
  <p>I <a href="http://django-rest-framework.org/api-guide/fields.html#core-arguments" rel="noreferrer">thought</a> <code>required=False</code> would do the job of bypassing the field if it doesn't exist. However, it is mentioned in the documentation that this affects deserialization rather than serialization.</p>
  
  <p>I'm getting the following error:</p>
  
  <pre><code>'Product' object has no attribute 'Classification'
  </code></pre>
  
  <p>Which is happening when I try to access <code>.data</code> of the serialized instance. (Doesn't this mean it's deserialization that's raising this?)</p>
  
  <p>This happens for instances that do not have <code>Classification</code>. If I omit <code>Classification</code> from the serializer class it works just fine.</p>
  
  <p>How do I correctly do this? Serialize an object with optional fields, that is.</p>