Serialize the given instance of Problem.

def serialize_problem(req, resp, problem):
    """Serialize the given instance of Problem."""
    preferred = req.client_prefers(
        ('application/json', 'application/problem+json')
    )
    if preferred is None:
        preferred = 'application/json'

    resp.data = problem.to_json().encode('utf-8')
    resp.content_type = preferred
    resp.append_header('Vary', 'Accept')