001/* 002 * Copyright 2012-2018 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.EnumMap; 020import java.util.Locale; 021import java.util.Map; 022import java.util.TimeZone; 023 024import com.fasterxml.jackson.annotation.JsonAutoDetect; 025import com.fasterxml.jackson.annotation.JsonInclude; 026import com.fasterxml.jackson.annotation.PropertyAccessor; 027import com.fasterxml.jackson.core.JsonGenerator; 028import com.fasterxml.jackson.core.JsonParser; 029import com.fasterxml.jackson.databind.DeserializationFeature; 030import com.fasterxml.jackson.databind.MapperFeature; 031import com.fasterxml.jackson.databind.SerializationFeature; 032 033import org.springframework.boot.context.properties.ConfigurationProperties; 034 035/** 036 * Configuration properties to configure Jackson. 037 * 038 * @author Andy Wilkinson 039 * @author Marcel Overdijk 040 * @author Johannes Edmeier 041 * @since 1.2.0 042 */ 043@ConfigurationProperties(prefix = "spring.jackson") 044public class JacksonProperties { 045 046 /** 047 * Date format string or a fully-qualified date format class name. For instance, 048 * `yyyy-MM-dd HH:mm:ss`. 049 */ 050 private String dateFormat; 051 052 /** 053 * Joda date time format string. If not configured, "date-format" is used as a 054 * fallback if it is configured with a format string. 055 */ 056 private String jodaDateTimeFormat; 057 058 /** 059 * One of the constants on Jackson's PropertyNamingStrategy. Can also be a 060 * fully-qualified class name of a PropertyNamingStrategy subclass. 061 */ 062 private String propertyNamingStrategy; 063 064 /** 065 * Jackson visibility thresholds that can be used to limit which methods (and fields) 066 * are auto-detected. 067 */ 068 private final Map<PropertyAccessor, JsonAutoDetect.Visibility> visibility = new EnumMap<>( 069 PropertyAccessor.class); 070 071 /** 072 * Jackson on/off features that affect the way Java objects are serialized. 073 */ 074 private final Map<SerializationFeature, Boolean> serialization = new EnumMap<>( 075 SerializationFeature.class); 076 077 /** 078 * Jackson on/off features that affect the way Java objects are deserialized. 079 */ 080 private final Map<DeserializationFeature, Boolean> deserialization = new EnumMap<>( 081 DeserializationFeature.class); 082 083 /** 084 * Jackson general purpose on/off features. 085 */ 086 private final Map<MapperFeature, Boolean> mapper = new EnumMap<>(MapperFeature.class); 087 088 /** 089 * Jackson on/off features for parsers. 090 */ 091 private final Map<JsonParser.Feature, Boolean> parser = new EnumMap<>( 092 JsonParser.Feature.class); 093 094 /** 095 * Jackson on/off features for generators. 096 */ 097 private final Map<JsonGenerator.Feature, Boolean> generator = new EnumMap<>( 098 JsonGenerator.Feature.class); 099 100 /** 101 * Controls the inclusion of properties during serialization. Configured with one of 102 * the values in Jackson's JsonInclude.Include enumeration. 103 */ 104 private JsonInclude.Include defaultPropertyInclusion; 105 106 /** 107 * Time zone used when formatting dates. For instance, "America/Los_Angeles" or 108 * "GMT+10". 109 */ 110 private TimeZone timeZone = null; 111 112 /** 113 * Locale used for formatting. 114 */ 115 private Locale locale; 116 117 public String getDateFormat() { 118 return this.dateFormat; 119 } 120 121 public void setDateFormat(String dateFormat) { 122 this.dateFormat = dateFormat; 123 } 124 125 public String getJodaDateTimeFormat() { 126 return this.jodaDateTimeFormat; 127 } 128 129 public void setJodaDateTimeFormat(String jodaDataTimeFormat) { 130 this.jodaDateTimeFormat = jodaDataTimeFormat; 131 } 132 133 public String getPropertyNamingStrategy() { 134 return this.propertyNamingStrategy; 135 } 136 137 public void setPropertyNamingStrategy(String propertyNamingStrategy) { 138 this.propertyNamingStrategy = propertyNamingStrategy; 139 } 140 141 public Map<PropertyAccessor, JsonAutoDetect.Visibility> getVisibility() { 142 return this.visibility; 143 } 144 145 public Map<SerializationFeature, Boolean> getSerialization() { 146 return this.serialization; 147 } 148 149 public Map<DeserializationFeature, Boolean> getDeserialization() { 150 return this.deserialization; 151 } 152 153 public Map<MapperFeature, Boolean> getMapper() { 154 return this.mapper; 155 } 156 157 public Map<JsonParser.Feature, Boolean> getParser() { 158 return this.parser; 159 } 160 161 public Map<JsonGenerator.Feature, Boolean> getGenerator() { 162 return this.generator; 163 } 164 165 public JsonInclude.Include getDefaultPropertyInclusion() { 166 return this.defaultPropertyInclusion; 167 } 168 169 public void setDefaultPropertyInclusion( 170 JsonInclude.Include defaultPropertyInclusion) { 171 this.defaultPropertyInclusion = defaultPropertyInclusion; 172 } 173 174 public TimeZone getTimeZone() { 175 return this.timeZone; 176 } 177 178 public void setTimeZone(TimeZone timeZone) { 179 this.timeZone = timeZone; 180 } 181 182 public Locale getLocale() { 183 return this.locale; 184 } 185 186 public void setLocale(Locale locale) { 187 this.locale = locale; 188 } 189 190}