'Serialize an type-id for `item`.'

def serialize_type_id(self, item, key, **context):

    TYPE_ID_SEP = '-'
    type_id = getattr(item, key)
    if (type_id is None):
        return None
    split = type_id.split(TYPE_ID_SEP, 1)
    return TYPE_ID_SEP.join([split[0], self.app.security.encode_id(split[1])])
