Integrate MRI projects for Neon
[netconf.git] / restconf / sal-rest-docgen / src / main / java / org / opendaylight / netconf / sal / rest / doc / jaxrs / JaxbContextResolver.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.sal.rest.doc.jaxrs;
9
10 import com.fasterxml.jackson.databind.ObjectMapper;
11 import javax.ws.rs.Consumes;
12 import javax.ws.rs.Produces;
13 import javax.ws.rs.core.MediaType;
14 import javax.ws.rs.ext.ContextResolver;
15 import javax.ws.rs.ext.Provider;
16 import org.opendaylight.netconf.sal.rest.doc.swagger.ApiDeclaration;
17
18 @Provider
19 @Consumes(MediaType.APPLICATION_JSON)
20 @Produces(MediaType.APPLICATION_JSON)
21 public class JaxbContextResolver implements ContextResolver<ObjectMapper> {
22
23     private final ObjectMapper ctx;
24
25     public JaxbContextResolver() {
26         ctx = new ObjectMapper();
27     }
28
29     @Override
30     public ObjectMapper getContext(final Class<?> klass) {
31         if (ApiDeclaration.class.isAssignableFrom(klass)) {
32             return ctx;
33         }
34
35         return null; // must return null so that JAX-RS can continue context search
36     }
37 }