'Convert the given serialized fields to the deserialized values by finding all references
and converting them.
:param jsonfields: the serialized copy of the xblock\'s fields'

def convert_references_to_keys(self, course_key, xblock_class, jsonfields, blocks):

    @contract(block_key='BlockUsageLocator    |    seq[2]')
    def robust_usage_key(block_key):
        "\n                                                create    a    course_key    relative    usage    key    for    the    block_key.    If    the    block_key    is    in    blocks,\n                                                use    its    correct    category;    otherwise,    use    'unknown'.\n                                                The    purpose    for    this    is    that    some    operations    add    pointers    as    they    build    up    the\n                                                structure    without    worrying    about    order    of    creation.    Because    the    category    of    the\n                                                usage_key    is    for    the    most    part    inert,    it's    better    to    hack    a    value    than    to    work\n                                                out    a    dependency    graph    algorithm    for    those    functions    which    may    prereference    blocks.\n                                                "
        if isinstance(block_key, BlockUsageLocator):
            return block_key.map_into_course(course_key)
        elif (not isinstance(block_key, BlockKey)):
            block_key = BlockKey(*block_key)
        try:
            return course_key.make_usage_key(block_key.type, block_key.id)
        except KeyError:
            return course_key.make_usage_key('unknown', block_key.id)
    xblock_class = self.mixologist.mix(xblock_class)
    output_fields = dict(jsonfields)
    for (field_name, value) in output_fields.iteritems():
        if value:
            try:
                field = xblock_class.fields.get(field_name)
            except AttributeError:
                continue
            if isinstance(field, Reference):
                output_fields[field_name] = robust_usage_key(value)
            elif isinstance(field, ReferenceList):
                output_fields[field_name] = [robust_usage_key(ele) for ele in value]
            elif isinstance(field, ReferenceValueDict):
                for (key, subvalue) in value.iteritems():
                    value[key] = robust_usage_key(subvalue)
    return output_fields
