Delete netconf
[controller.git] / opendaylight / md-sal / sal-rest-docgen / src / main / java / org / opendaylight / controller / 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.controller.sal.rest.doc.jaxrs;
9
10 import javax.ws.rs.Consumes;
11 import javax.ws.rs.Produces;
12 import javax.ws.rs.core.MediaType;
13 import javax.ws.rs.ext.ContextResolver;
14 import javax.ws.rs.ext.Provider;
15
16 import org.opendaylight.controller.sal.rest.doc.swagger.ApiDeclaration;
17
18 import com.fasterxml.jackson.annotation.JsonInclude;
19 import com.fasterxml.jackson.databind.ObjectMapper;
20 import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;
21
22 @Provider
23 @Consumes(MediaType.APPLICATION_JSON)
24 @Produces(MediaType.APPLICATION_JSON)
25 public class JaxbContextResolver implements ContextResolver<ObjectMapper> {
26
27     private final ObjectMapper ctx;
28
29     public JaxbContextResolver() {
30         ctx = new ObjectMapper();
31         ctx.registerModule(new JsonOrgModule());
32         ctx.getSerializationConfig().withSerializationInclusion(JsonInclude.Include.ALWAYS);
33     }
34
35     @Override
36     public ObjectMapper getContext(Class<?> aClass) {
37
38         if (ApiDeclaration.class.isAssignableFrom(aClass)) {
39             return ctx;
40         }
41
42         return null;// must return null so that jax-rs can continue context
43                     // search
44     }
45 }