001/*
002 * Copyright 2012-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.autoconfigure.jackson;
018
019import java.util.HashMap;
020import java.util.Locale;
021import java.util.Map;
022import java.util.TimeZone;
023
024import com.fasterxml.jackson.annotation.JsonInclude;
025import com.fasterxml.jackson.core.JsonGenerator;
026import com.fasterxml.jackson.core.JsonParser;
027import com.fasterxml.jackson.databind.DeserializationFeature;
028import com.fasterxml.jackson.databind.MapperFeature;
029import com.fasterxml.jackson.databind.SerializationFeature;
030
031import org.springframework.boot.context.properties.ConfigurationProperties;
032
033/**
034 * Configuration properties to configure Jackson.
035 *
036 * @author Andy Wilkinson
037 * @author Marcel Overdijk
038 * @author Johannes Edmeier
039 * @since 1.2.0
040 */
041@ConfigurationProperties(prefix = "spring.jackson")
042public class JacksonProperties {
043
044        /**
045         * Date format string (yyyy-MM-dd HH:mm:ss), or a fully-qualified date format class
046         * name.
047         */
048        private String dateFormat;
049
050        /**
051         * Joda date time format string (yyyy-MM-dd HH:mm:ss). If not configured,
052         * "date-format" will be used as a fallback if it is configured with a format string.
053         */
054        private String jodaDateTimeFormat;
055
056        /**
057         * One of the constants on Jackson's PropertyNamingStrategy
058         * (CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES). Can also be a fully-qualified class
059         * name of a PropertyNamingStrategy subclass.
060         */
061        private String propertyNamingStrategy;
062
063        /**
064         * Jackson on/off features that affect the way Java objects are serialized.
065         */
066        private Map<SerializationFeature, Boolean> serialization = new HashMap<SerializationFeature, Boolean>();
067
068        /**
069         * Jackson on/off features that affect the way Java objects are deserialized.
070         */
071        private Map<DeserializationFeature, Boolean> deserialization = new HashMap<DeserializationFeature, Boolean>();
072
073        /**
074         * Jackson general purpose on/off features.
075         */
076        private Map<MapperFeature, Boolean> mapper = new HashMap<MapperFeature, Boolean>();
077
078        /**
079         * Jackson on/off features for parsers.
080         */
081        private Map<JsonParser.Feature, Boolean> parser = new HashMap<JsonParser.Feature, Boolean>();
082
083        /**
084         * Jackson on/off features for generators.
085         */
086        private Map<JsonGenerator.Feature, Boolean> generator = new HashMap<JsonGenerator.Feature, Boolean>();
087
088        /**
089         * Controls the inclusion of properties during serialization. Configured with one of
090         * the values in Jackson's JsonInclude.Include enumeration.
091         */
092        private JsonInclude.Include defaultPropertyInclusion;
093
094        /**
095         * Time zone used when formatting dates. Configured using any recognized time zone
096         * identifier, for example "America/Los_Angeles" or "GMT+10".
097         */
098        private TimeZone timeZone = null;
099
100        /**
101         * Locale used for formatting.
102         */
103        private Locale locale;
104
105        public String getDateFormat() {
106                return this.dateFormat;
107        }
108
109        public void setDateFormat(String dateFormat) {
110                this.dateFormat = dateFormat;
111        }
112
113        public String getJodaDateTimeFormat() {
114                return this.jodaDateTimeFormat;
115        }
116
117        public void setJodaDateTimeFormat(String jodaDataTimeFormat) {
118                this.jodaDateTimeFormat = jodaDataTimeFormat;
119        }
120
121        public String getPropertyNamingStrategy() {
122                return this.propertyNamingStrategy;
123        }
124
125        public void setPropertyNamingStrategy(String propertyNamingStrategy) {
126                this.propertyNamingStrategy = propertyNamingStrategy;
127        }
128
129        public Map<SerializationFeature, Boolean> getSerialization() {
130                return this.serialization;
131        }
132
133        public Map<DeserializationFeature, Boolean> getDeserialization() {
134                return this.deserialization;
135        }
136
137        public Map<MapperFeature, Boolean> getMapper() {
138                return this.mapper;
139        }
140
141        public Map<JsonParser.Feature, Boolean> getParser() {
142                return this.parser;
143        }
144
145        public Map<JsonGenerator.Feature, Boolean> getGenerator() {
146                return this.generator;
147        }
148
149        public JsonInclude.Include getDefaultPropertyInclusion() {
150                return this.defaultPropertyInclusion;
151        }
152
153        public void setDefaultPropertyInclusion(
154                        JsonInclude.Include defaultPropertyInclusion) {
155                this.defaultPropertyInclusion = defaultPropertyInclusion;
156        }
157
158        public TimeZone getTimeZone() {
159                return this.timeZone;
160        }
161
162        public void setTimeZone(TimeZone timeZone) {
163                this.timeZone = timeZone;
164        }
165
166        public Locale getLocale() {
167                return this.locale;
168        }
169
170        public void setLocale(Locale locale) {
171                this.locale = locale;
172        }
173
174}