Merge "Application.java: Fixed sonar issue"
[ccsdk/apps.git] / ms / neng / src / main / java / org / onap / ccsdk / apps / ms / neng / core / JerseyConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK.apps
4  * ================================================================================
5  * Copyright (C) 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
21 package org.onap.ccsdk.apps.ms.neng.core;
22
23 import com.fasterxml.jackson.annotation.JsonInclude;
24 import com.fasterxml.jackson.databind.DeserializationFeature;
25 import com.fasterxml.jackson.databind.MapperFeature;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import com.fasterxml.jackson.databind.SerializationFeature;
28 import javax.ws.rs.ApplicationPath;
29 import org.glassfish.jersey.server.ResourceConfig;
30 import org.glassfish.jersey.servlet.ServletProperties;
31 import org.onap.ccsdk.apps.ms.neng.core.service.rs.RestServiceImpl;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.context.annotation.Bean;
34 import org.springframework.context.annotation.Primary;
35 import org.springframework.stereotype.Component;
36
37 /**
38  * Configuration of the REST framework.
39  */
40 @Component
41 @ApplicationPath("/")
42 public class JerseyConfiguration extends ResourceConfig {
43
44     @Autowired
45     public JerseyConfiguration() {
46         register(RestServiceImpl.class);
47         property(ServletProperties.FILTER_FORWARD_ON_404, true);
48     }
49     
50     /**
51      * Builds the bean configuring Jackson for JSON serialization.
52      */
53     @Bean
54     @Primary
55     public ObjectMapper objectMapper() {
56         ObjectMapper objectMapper = new ObjectMapper();
57         objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
58         objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
59         objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
60         objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
61         return objectMapper;
62     }
63 }