'Convert any references to their serialized form. Handle some references already being unicoded
because the client passed them that way and nothing above this layer did the necessary deserialization.
Remove any fields which split or its kvs computes or adds but does not want persisted.
:param fields: a dict of fields'

def _serialize_fields(self, category, fields):

    assert isinstance(fields, dict)
    xblock_class = XBlock.load_class(category, self.default_class)
    xblock_class = self.mixologist.mix(xblock_class)
    def reference_block_id(reference):
        '\n                                                Handle    client    possibly    setting    field    to    strings    rather    than    keys    to    get    the    block_id\n                                                '
        if isinstance(reference, basestring):
            reference = BlockUsageLocator.from_string(reference)
        elif isinstance(reference, BlockKey):
            return reference
        return BlockKey.from_usage_key(reference)
    for (field_name, value) in fields.iteritems():
        if (value is not None):
            if isinstance(xblock_class.fields[field_name], Reference):
                fields[field_name] = reference_block_id(value)
            elif isinstance(xblock_class.fields[field_name], ReferenceList):
                fields[field_name] = [reference_block_id(ele) for ele in value]
            elif isinstance(xblock_class.fields[field_name], ReferenceValueDict):
                for (key, subvalue) in value.iteritems():
                    value[key] = reference_block_id(subvalue)
            elif (not isinstance(value, datetime.datetime)):
                fields[field_name] = xblock_class.fields[field_name].to_json(value)
    return fields
