'Encode a GeoJSON dict into an GeoJSON object.
Assumes the caller knows that the dict should satisfy a GeoJSON type.'

@classmethod
def to_instance(cls, ob, default=None, strict=False):

    if ((ob is None) and (default is not None)):
        instance = default()
    elif isinstance(ob, GeoJSON):
        instance = ob
    else:
        mapping = to_mapping(ob)
        d = dict(((str(k), mapping[k]) for k in mapping))
        try:
            type_ = d.pop('type')
            geojson_factory = getattr(geojson.factory, type_)
            if (not issubclass(geojson_factory, GeoJSON)):
                raise TypeError(('                                                                                Not    a    valid    GeoJSON    type:\n                                                                                %r    (geojson_factory:    %r,    cls:    %r)\n                                                                                ' % (type_, geojson_factory, cls)))
            instance = geojson_factory(**d)
        except (AttributeError, KeyError) as invalid:
            if (not strict):
                instance = ob
            else:
                msg = 'Cannot    coerce    %r    into    a    valid    GeoJSON    structure:    %s'
                msg %= (ob, invalid)
                raise ValueError(msg)
    return instance
