A decorator used to return a JSON response with a dict
        representation of the model instance.  It expects the decorated function
        to return a Model instance. It then converts the instance to dicts
        and serializes it into a json response

        Examples:

            >>> @app.route('/api/shipments/<id>')
            ... @as_obj
            ... def get_shipment(id):
            ...     return Shipment.get(id)

def as_obj(func):
    """ A decorator used to return a JSON response with a dict
        representation of the model instance.  It expects the decorated function
        to return a Model instance. It then converts the instance to dicts
        and serializes it into a json response

        Examples:

            >>> @app.route('/api/shipments/<id>')
            ... @as_obj
            ... def get_shipment(id):
            ...     return Shipment.get(id)
    """
    @wraps(func)
    def wrapper(*args, **kwargs):
        response = func(*args, **kwargs)
        return render_json_obj_with_requested_structure(response)
    return wrapper