Initial commit with all the necessary files
[aai/aai-common.git] / aai-core / src / main / java / org / openecomp / aai / restcore / CustomJacksonJaxBJsonProvider.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
4  * ================================================================================
5  * Copyright (C) 2017 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
21 package org.openecomp.aai.restcore;
22
23 import javax.ws.rs.ext.Provider;
24
25 import com.fasterxml.jackson.annotation.JsonInclude;
26 import com.fasterxml.jackson.databind.DeserializationFeature;
27 import com.fasterxml.jackson.databind.ObjectMapper;
28 import com.fasterxml.jackson.databind.SerializationFeature;
29 import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
30 import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
31
32 /**
33  * The Class CustomJacksonJaxBJsonProvider.
34  */
35 @Provider
36 public class CustomJacksonJaxBJsonProvider extends JacksonJaxbJsonProvider {
37
38         private static ObjectMapper commonMapper = null;
39
40             /**
41          * Instantiates a new custom jackson jax B json provider.
42          */
43         public CustomJacksonJaxBJsonProvider() {
44                 if (commonMapper == null) {
45                     ObjectMapper mapper = new ObjectMapper();
46
47                     mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
48                     
49                     mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
50                     mapper.configure(SerializationFeature.INDENT_OUTPUT, false);
51                     mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
52
53                     mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
54                     mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
55
56                     mapper.registerModule(new JaxbAnnotationModule());
57
58                     commonMapper = mapper;
59                 }
60                 super.setMapper(commonMapper);
61             }
62             
63             /**
64          * Gets the mapper.
65          *
66          * @return the mapper
67          */
68         public ObjectMapper getMapper() {
69                 return commonMapper;
70             }
71 }