2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.northbound.commons;
11 import javax.ws.rs.Consumes;
12 import javax.ws.rs.core.GenericEntity;
13 import javax.ws.rs.core.MediaType;
14 import javax.ws.rs.core.Response;
15 import javax.ws.rs.ext.ExceptionMapper;
16 import javax.ws.rs.ext.Provider;
18 import org.codehaus.jackson.JsonProcessingException;
21 * A custom exception mapper for handling Jackson JsonProcessingException types
24 @Consumes({MediaType.APPLICATION_JSON})
25 public class JacksonJsonProcessingExceptionMapper
26 implements ExceptionMapper<JsonProcessingException>
30 public Response toResponse(JsonProcessingException exception) {
31 GenericEntity<String> entity =
32 new GenericEntity<String>(exception.getMessage()) {};
33 return Response.status(Response.Status.BAD_REQUEST).entity(entity).build();