@classmethod
def encode_conjure_union_type(cls, obj):
    """Encodes a conjure union into json"""
    encoded = {}
    encoded['type'] = obj.type
    for attr, field_definition in obj._options().items():
        if field_definition.identifier == obj.type:
            attribute = attr
            break
    else:
        raise ValueError('could not find attribute for union ' +
            'member {0} of type {1}'.format(obj.type, obj.__class__))
    defined_field_definition = obj._options()[attribute]
    encoded[defined_field_definition.identifier] = cls.do_encode(getattr(
        obj, attribute))
    return encoded
