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 com.fasterxml.jackson.core.JsonProcessingException;
22 * A custom exception mapper for handling Jackson JsonProcessingException types
25 @Consumes({MediaType.APPLICATION_JSON})
26 public class JacksonJsonProcessingExceptionMapper
27 implements ExceptionMapper<JsonProcessingException>
31 public Response toResponse(JsonProcessingException exception) {
32 GenericEntity<String> entity =
33 new GenericEntity<String>(exception.getMessage()) {};
34 return Response.status(Response.Status.BAD_REQUEST).entity(entity).build();