View Javadoc
1   /*
2    * Licensed under the Apache License, Version 2.0 (the "License");
3    * you may not use this file except in compliance with the License.
4    * You may obtain a copy of the License at
5    *
6    * http://www.apache.org/licenses/LICENSE-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS,
10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   * See the License for the specific language governing permissions and
12   * limitations under the License.
13   */
14  package com.addthis.codec.jackson;
15  
16  import javax.validation.Validation;
17  import javax.validation.Validator;
18  
19  import com.addthis.codec.plugins.PluginRegistry;
20  
21  import com.fasterxml.jackson.databind.ObjectMapper;
22  import com.typesafe.config.ConfigFactory;
23  
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  final class DefaultCodecJackson {
28      private static final Logger log;
29  
30      static final ObjectMapper DEFAULT_MAPPER;
31      static final Validator DEFAULT_VALIDATOR;
32      static final CodecJackson DEFAULT_CODEC;
33  
34      static {
35          log = LoggerFactory.getLogger(DefaultCodecJackson.class);
36          DEFAULT_MAPPER = Jackson.newObjectMapper(PluginRegistry.defaultRegistry());
37          log.trace("initialized default codec mapper {}", DEFAULT_MAPPER);
38          DEFAULT_VALIDATOR =  Validation.buildDefaultValidatorFactory().getValidator();
39          log.trace("initialized default codec validator {}", DEFAULT_VALIDATOR);
40          DEFAULT_CODEC = new CodecJackson(DEFAULT_MAPPER, PluginRegistry.defaultRegistry(),
41                                           ConfigFactory.load(), DEFAULT_VALIDATOR);
42          log.trace("initialized default codec jackson {}", DEFAULT_CODEC);
43      }
44  }