Skip to content

Commit a044d91

Browse files
committed
Add nullability annotations to module/spring-boot-gson
See gh-46587
1 parent 46ff56c commit a044d91

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

module/spring-boot-gson/src/main/java/org/springframework/boot/gson/autoconfigure/GsonProperties.java

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.gson.FieldNamingPolicy;
2020
import com.google.gson.Gson;
2121
import com.google.gson.LongSerializationPolicy;
22+
import org.jspecify.annotations.Nullable;
2223

2324
import org.springframework.boot.context.properties.ConfigurationProperties;
2425

@@ -35,150 +36,150 @@ public class GsonProperties {
3536
* Whether to generate non-executable JSON by prefixing the output with some special
3637
* text.
3738
*/
38-
private Boolean generateNonExecutableJson;
39+
private @Nullable Boolean generateNonExecutableJson;
3940

4041
/**
4142
* Whether to exclude all fields from consideration for serialization or
4243
* deserialization that do not have the "Expose" annotation.
4344
*/
44-
private Boolean excludeFieldsWithoutExposeAnnotation;
45+
private @Nullable Boolean excludeFieldsWithoutExposeAnnotation;
4546

4647
/**
4748
* Whether to serialize null fields.
4849
*/
49-
private Boolean serializeNulls;
50+
private @Nullable Boolean serializeNulls;
5051

5152
/**
5253
* Whether to enable serialization of complex map keys (i.e. non-primitives).
5354
*/
54-
private Boolean enableComplexMapKeySerialization;
55+
private @Nullable Boolean enableComplexMapKeySerialization;
5556

5657
/**
5758
* Whether to exclude inner classes during serialization.
5859
*/
59-
private Boolean disableInnerClassSerialization;
60+
private @Nullable Boolean disableInnerClassSerialization;
6061

6162
/**
6263
* Serialization policy for Long and long types.
6364
*/
64-
private LongSerializationPolicy longSerializationPolicy;
65+
private @Nullable LongSerializationPolicy longSerializationPolicy;
6566

6667
/**
6768
* Naming policy that should be applied to an object's field during serialization and
6869
* deserialization.
6970
*/
70-
private FieldNamingPolicy fieldNamingPolicy;
71+
private @Nullable FieldNamingPolicy fieldNamingPolicy;
7172

7273
/**
7374
* Whether to output serialized JSON that fits in a page for pretty printing.
7475
*/
75-
private Boolean prettyPrinting;
76+
private @Nullable Boolean prettyPrinting;
7677

7778
/**
7879
* Sets how strictly the RFC 8259 specification will be enforced when reading and
7980
* writing JSON.
8081
*/
81-
private Strictness strictness;
82+
private @Nullable Strictness strictness;
8283

8384
/**
8485
* Whether to disable the escaping of HTML characters such as '<', '>', etc.
8586
*/
86-
private Boolean disableHtmlEscaping;
87+
private @Nullable Boolean disableHtmlEscaping;
8788

8889
/**
8990
* Format to use when serializing Date objects.
9091
*/
91-
private String dateFormat;
92+
private @Nullable String dateFormat;
9293

93-
public Boolean getGenerateNonExecutableJson() {
94+
public @Nullable Boolean getGenerateNonExecutableJson() {
9495
return this.generateNonExecutableJson;
9596
}
9697

97-
public void setGenerateNonExecutableJson(Boolean generateNonExecutableJson) {
98+
public void setGenerateNonExecutableJson(@Nullable Boolean generateNonExecutableJson) {
9899
this.generateNonExecutableJson = generateNonExecutableJson;
99100
}
100101

101-
public Boolean getExcludeFieldsWithoutExposeAnnotation() {
102+
public @Nullable Boolean getExcludeFieldsWithoutExposeAnnotation() {
102103
return this.excludeFieldsWithoutExposeAnnotation;
103104
}
104105

105-
public void setExcludeFieldsWithoutExposeAnnotation(Boolean excludeFieldsWithoutExposeAnnotation) {
106+
public void setExcludeFieldsWithoutExposeAnnotation(@Nullable Boolean excludeFieldsWithoutExposeAnnotation) {
106107
this.excludeFieldsWithoutExposeAnnotation = excludeFieldsWithoutExposeAnnotation;
107108
}
108109

109-
public Boolean getSerializeNulls() {
110+
public @Nullable Boolean getSerializeNulls() {
110111
return this.serializeNulls;
111112
}
112113

113-
public void setSerializeNulls(Boolean serializeNulls) {
114+
public void setSerializeNulls(@Nullable Boolean serializeNulls) {
114115
this.serializeNulls = serializeNulls;
115116
}
116117

117-
public Boolean getEnableComplexMapKeySerialization() {
118+
public @Nullable Boolean getEnableComplexMapKeySerialization() {
118119
return this.enableComplexMapKeySerialization;
119120
}
120121

121-
public void setEnableComplexMapKeySerialization(Boolean enableComplexMapKeySerialization) {
122+
public void setEnableComplexMapKeySerialization(@Nullable Boolean enableComplexMapKeySerialization) {
122123
this.enableComplexMapKeySerialization = enableComplexMapKeySerialization;
123124
}
124125

125-
public Boolean getDisableInnerClassSerialization() {
126+
public @Nullable Boolean getDisableInnerClassSerialization() {
126127
return this.disableInnerClassSerialization;
127128
}
128129

129-
public void setDisableInnerClassSerialization(Boolean disableInnerClassSerialization) {
130+
public void setDisableInnerClassSerialization(@Nullable Boolean disableInnerClassSerialization) {
130131
this.disableInnerClassSerialization = disableInnerClassSerialization;
131132
}
132133

133-
public LongSerializationPolicy getLongSerializationPolicy() {
134+
public @Nullable LongSerializationPolicy getLongSerializationPolicy() {
134135
return this.longSerializationPolicy;
135136
}
136137

137-
public void setLongSerializationPolicy(LongSerializationPolicy longSerializationPolicy) {
138+
public void setLongSerializationPolicy(@Nullable LongSerializationPolicy longSerializationPolicy) {
138139
this.longSerializationPolicy = longSerializationPolicy;
139140
}
140141

141-
public FieldNamingPolicy getFieldNamingPolicy() {
142+
public @Nullable FieldNamingPolicy getFieldNamingPolicy() {
142143
return this.fieldNamingPolicy;
143144
}
144145

145-
public void setFieldNamingPolicy(FieldNamingPolicy fieldNamingPolicy) {
146+
public void setFieldNamingPolicy(@Nullable FieldNamingPolicy fieldNamingPolicy) {
146147
this.fieldNamingPolicy = fieldNamingPolicy;
147148
}
148149

149-
public Boolean getPrettyPrinting() {
150+
public @Nullable Boolean getPrettyPrinting() {
150151
return this.prettyPrinting;
151152
}
152153

153-
public void setPrettyPrinting(Boolean prettyPrinting) {
154+
public void setPrettyPrinting(@Nullable Boolean prettyPrinting) {
154155
this.prettyPrinting = prettyPrinting;
155156
}
156157

157-
public Strictness getStrictness() {
158+
public @Nullable Strictness getStrictness() {
158159
return this.strictness;
159160
}
160161

161-
public void setStrictness(Strictness strictness) {
162+
public void setStrictness(@Nullable Strictness strictness) {
162163
this.strictness = strictness;
163164
}
164165

165-
public void setLenient(Boolean lenient) {
166+
public void setLenient(@Nullable Boolean lenient) {
166167
setStrictness((lenient != null && lenient) ? Strictness.LENIENT : Strictness.STRICT);
167168
}
168169

169-
public Boolean getDisableHtmlEscaping() {
170+
public @Nullable Boolean getDisableHtmlEscaping() {
170171
return this.disableHtmlEscaping;
171172
}
172173

173-
public void setDisableHtmlEscaping(Boolean disableHtmlEscaping) {
174+
public void setDisableHtmlEscaping(@Nullable Boolean disableHtmlEscaping) {
174175
this.disableHtmlEscaping = disableHtmlEscaping;
175176
}
176177

177-
public String getDateFormat() {
178+
public @Nullable String getDateFormat() {
178179
return this.dateFormat;
179180
}
180181

181-
public void setDateFormat(String dateFormat) {
182+
public void setDateFormat(@Nullable String dateFormat) {
182183
this.dateFormat = dateFormat;
183184
}
184185

module/spring-boot-gson/src/main/java/org/springframework/boot/gson/autoconfigure/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for GSON.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.gson.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)