Update the license for 2017-2018 license
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / restcore / CustomJacksonJaxBJsonProvider.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.aai.restcore;
21
22 import javax.ws.rs.ext.Provider;
23
24 import com.fasterxml.jackson.annotation.JsonInclude;
25 import com.fasterxml.jackson.databind.DeserializationFeature;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import com.fasterxml.jackson.databind.SerializationFeature;
28 import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
29 import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
30
31 /**
32  * The Class CustomJacksonJaxBJsonProvider.
33  */
34 @Provider
35 public class CustomJacksonJaxBJsonProvider extends JacksonJaxbJsonProvider {
36
37         private static ObjectMapper commonMapper = null;
38
39             /**
40          * Instantiates a new custom jackson jax B json provider.
41          */
42         public CustomJacksonJaxBJsonProvider() {
43                 if (commonMapper == null) {
44                     ObjectMapper mapper = new ObjectMapper();
45
46                     mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
47                     
48                     mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
49                     mapper.configure(SerializationFeature.INDENT_OUTPUT, false);
50                     mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
51
52                     mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
53                     mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
54
55                     mapper.registerModule(new JaxbAnnotationModule());
56
57                     commonMapper = mapper;
58                 }
59                 super.setMapper(commonMapper);
60             }
61             
62             /**
63          * Gets the mapper.
64          *
65          * @return the mapper
66          */
67         public ObjectMapper getMapper() {
68                 return commonMapper;
69             }
70 }