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.gson;
018
019import com.google.gson.FieldNamingPolicy;
020import com.google.gson.Gson;
021import com.google.gson.LongSerializationPolicy;
022
023import org.springframework.boot.context.properties.ConfigurationProperties;
024
025/**
026 * Configuration properties to configure {@link Gson}.
027 *
028 * @author Ivan Golovko
029 * @since 2.0.0
030 */
031@ConfigurationProperties(prefix = "spring.gson")
032public class GsonProperties {
033
034        /**
035         * Whether to generate non executable JSON by prefixing the output with some special
036         * text.
037         */
038        private Boolean generateNonExecutableJson;
039
040        /**
041         * Whether to exclude all fields from consideration for serialization or
042         * deserialization that do not have the "Expose" annotation.
043         */
044        private Boolean excludeFieldsWithoutExposeAnnotation;
045
046        /**
047         * Whether to serialize null fields.
048         */
049        private Boolean serializeNulls;
050
051        /**
052         * Whether to enable serialization of complex map keys (i.e. non-primitives).
053         */
054        private Boolean enableComplexMapKeySerialization;
055
056        /**
057         * Whether to exclude inner classes during serialization.
058         */
059        private Boolean disableInnerClassSerialization;
060
061        /**
062         * Serialization policy for Long and long types.
063         */
064        private LongSerializationPolicy longSerializationPolicy;
065
066        /**
067         * Naming policy that should be applied to an object's field during serialization and
068         * deserialization.
069         */
070        private FieldNamingPolicy fieldNamingPolicy;
071
072        /**
073         * Whether to output serialized JSON that fits in a page for pretty printing.
074         */
075        private Boolean prettyPrinting;
076
077        /**
078         * Whether to be lenient about parsing JSON that doesn't conform to RFC 4627.
079         */
080        private Boolean lenient;
081
082        /**
083         * Whether to disable the escaping of HTML characters such as '<', '>', etc.
084         */
085        private Boolean disableHtmlEscaping;
086
087        /**
088         * Format to use when serializing Date objects.
089         */
090        private String dateFormat;
091
092        public Boolean getGenerateNonExecutableJson() {
093                return this.generateNonExecutableJson;
094        }
095
096        public void setGenerateNonExecutableJson(Boolean generateNonExecutableJson) {
097                this.generateNonExecutableJson = generateNonExecutableJson;
098        }
099
100        public Boolean getExcludeFieldsWithoutExposeAnnotation() {
101                return this.excludeFieldsWithoutExposeAnnotation;
102        }
103
104        public void setExcludeFieldsWithoutExposeAnnotation(
105                        Boolean excludeFieldsWithoutExposeAnnotation) {
106                this.excludeFieldsWithoutExposeAnnotation = excludeFieldsWithoutExposeAnnotation;
107        }
108
109        public Boolean getSerializeNulls() {
110                return this.serializeNulls;
111        }
112
113        public void setSerializeNulls(Boolean serializeNulls) {
114                this.serializeNulls = serializeNulls;
115        }
116
117        public Boolean getEnableComplexMapKeySerialization() {
118                return this.enableComplexMapKeySerialization;
119        }
120
121        public void setEnableComplexMapKeySerialization(
122                        Boolean enableComplexMapKeySerialization) {
123                this.enableComplexMapKeySerialization = enableComplexMapKeySerialization;
124        }
125
126        public Boolean getDisableInnerClassSerialization() {
127                return this.disableInnerClassSerialization;
128        }
129
130        public void setDisableInnerClassSerialization(
131                        Boolean disableInnerClassSerialization) {
132                this.disableInnerClassSerialization = disableInnerClassSerialization;
133        }
134
135        public LongSerializationPolicy getLongSerializationPolicy() {
136                return this.longSerializationPolicy;
137        }
138
139        public void setLongSerializationPolicy(
140                        LongSerializationPolicy longSerializationPolicy) {
141                this.longSerializationPolicy = longSerializationPolicy;
142        }
143
144        public FieldNamingPolicy getFieldNamingPolicy() {
145                return this.fieldNamingPolicy;
146        }
147
148        public void setFieldNamingPolicy(FieldNamingPolicy fieldNamingPolicy) {
149                this.fieldNamingPolicy = fieldNamingPolicy;
150        }
151
152        public Boolean getPrettyPrinting() {
153                return this.prettyPrinting;
154        }
155
156        public void setPrettyPrinting(Boolean prettyPrinting) {
157                this.prettyPrinting = prettyPrinting;
158        }
159
160        public Boolean getLenient() {
161                return this.lenient;
162        }
163
164        public void setLenient(Boolean lenient) {
165                this.lenient = lenient;
166        }
167
168        public Boolean getDisableHtmlEscaping() {
169                return this.disableHtmlEscaping;
170        }
171
172        public void setDisableHtmlEscaping(Boolean disableHtmlEscaping) {
173                this.disableHtmlEscaping = disableHtmlEscaping;
174        }
175
176        public String getDateFormat() {
177                return this.dateFormat;
178        }
179
180        public void setDateFormat(String dateFormat) {
181                this.dateFormat = dateFormat;
182        }
183
184}