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