28
28
import static com .google .gson .Gson .DEFAULT_SPECIALIZE_FLOAT_VALUES ;
29
29
import static com .google .gson .Gson .DEFAULT_USE_JDK_UNSAFE ;
30
30
31
+ import com .google .errorprone .annotations .CanIgnoreReturnValue ;
31
32
import com .google .gson .annotations .Since ;
32
33
import com .google .gson .annotations .Until ;
33
34
import com .google .gson .internal .$Gson$Preconditions ;
@@ -159,6 +160,7 @@ public GsonBuilder() {
159
160
* @see Since
160
161
* @see Until
161
162
*/
163
+ @ CanIgnoreReturnValue
162
164
public GsonBuilder setVersion (double version ) {
163
165
if (Double .isNaN (version ) || version < 0.0 ) {
164
166
throw new IllegalArgumentException ("Invalid version: " + version );
@@ -181,6 +183,7 @@ public GsonBuilder setVersion(double version) {
181
183
* {@link java.lang.reflect.Modifier#STATIC}.
182
184
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
183
185
*/
186
+ @ CanIgnoreReturnValue
184
187
public GsonBuilder excludeFieldsWithModifiers (int ... modifiers ) {
185
188
Objects .requireNonNull (modifiers );
186
189
excluder = excluder .withModifiers (modifiers );
@@ -196,6 +199,7 @@ public GsonBuilder excludeFieldsWithModifiers(int... modifiers) {
196
199
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
197
200
* @since 1.3
198
201
*/
202
+ @ CanIgnoreReturnValue
199
203
public GsonBuilder generateNonExecutableJson () {
200
204
this .generateNonExecutableJson = true ;
201
205
return this ;
@@ -210,6 +214,7 @@ public GsonBuilder generateNonExecutableJson() {
210
214
*
211
215
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
212
216
*/
217
+ @ CanIgnoreReturnValue
213
218
public GsonBuilder excludeFieldsWithoutExposeAnnotation () {
214
219
excluder = excluder .excludeFieldsWithoutExposeAnnotation ();
215
220
return this ;
@@ -222,6 +227,7 @@ public GsonBuilder excludeFieldsWithoutExposeAnnotation() {
222
227
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
223
228
* @since 1.2
224
229
*/
230
+ @ CanIgnoreReturnValue
225
231
public GsonBuilder serializeNulls () {
226
232
this .serializeNulls = true ;
227
233
return this ;
@@ -306,6 +312,7 @@ public GsonBuilder serializeNulls() {
306
312
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
307
313
* @since 1.7
308
314
*/
315
+ @ CanIgnoreReturnValue
309
316
public GsonBuilder enableComplexMapKeySerialization () {
310
317
complexMapKeySerialization = true ;
311
318
return this ;
@@ -330,6 +337,7 @@ public GsonBuilder enableComplexMapKeySerialization() {
330
337
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
331
338
* @since 1.3
332
339
*/
340
+ @ CanIgnoreReturnValue
333
341
public GsonBuilder disableInnerClassSerialization () {
334
342
excluder = excluder .disableInnerClassSerialization ();
335
343
return this ;
@@ -343,6 +351,7 @@ public GsonBuilder disableInnerClassSerialization() {
343
351
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
344
352
* @since 1.3
345
353
*/
354
+ @ CanIgnoreReturnValue
346
355
public GsonBuilder setLongSerializationPolicy (LongSerializationPolicy serializationPolicy ) {
347
356
this .longSerializationPolicy = Objects .requireNonNull (serializationPolicy );
348
357
return this ;
@@ -354,6 +363,7 @@ public GsonBuilder setLongSerializationPolicy(LongSerializationPolicy serializat
354
363
*
355
364
* <p>This method just delegates to {@link #setFieldNamingStrategy(FieldNamingStrategy)}.
356
365
*/
366
+ @ CanIgnoreReturnValue
357
367
public GsonBuilder setFieldNamingPolicy (FieldNamingPolicy namingConvention ) {
358
368
return setFieldNamingStrategy (namingConvention );
359
369
}
@@ -370,6 +380,7 @@ public GsonBuilder setFieldNamingPolicy(FieldNamingPolicy namingConvention) {
370
380
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
371
381
* @since 1.3
372
382
*/
383
+ @ CanIgnoreReturnValue
373
384
public GsonBuilder setFieldNamingStrategy (FieldNamingStrategy fieldNamingStrategy ) {
374
385
this .fieldNamingPolicy = Objects .requireNonNull (fieldNamingStrategy );
375
386
return this ;
@@ -383,6 +394,7 @@ public GsonBuilder setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrateg
383
394
* @see ToNumberPolicy#DOUBLE The default object-to-number strategy
384
395
* @since 2.8.9
385
396
*/
397
+ @ CanIgnoreReturnValue
386
398
public GsonBuilder setObjectToNumberStrategy (ToNumberStrategy objectToNumberStrategy ) {
387
399
this .objectToNumberStrategy = Objects .requireNonNull (objectToNumberStrategy );
388
400
return this ;
@@ -396,6 +408,7 @@ public GsonBuilder setObjectToNumberStrategy(ToNumberStrategy objectToNumberStra
396
408
* @see ToNumberPolicy#LAZILY_PARSED_NUMBER The default number-to-number strategy
397
409
* @since 2.8.9
398
410
*/
411
+ @ CanIgnoreReturnValue
399
412
public GsonBuilder setNumberToNumberStrategy (ToNumberStrategy numberToNumberStrategy ) {
400
413
this .numberToNumberStrategy = Objects .requireNonNull (numberToNumberStrategy );
401
414
return this ;
@@ -427,6 +440,7 @@ public GsonBuilder setNumberToNumberStrategy(ToNumberStrategy numberToNumberStra
427
440
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
428
441
* @since 1.4
429
442
*/
443
+ @ CanIgnoreReturnValue
430
444
public GsonBuilder setExclusionStrategies (ExclusionStrategy ... strategies ) {
431
445
Objects .requireNonNull (strategies );
432
446
for (ExclusionStrategy strategy : strategies ) {
@@ -450,6 +464,7 @@ public GsonBuilder setExclusionStrategies(ExclusionStrategy... strategies) {
450
464
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
451
465
* @since 1.7
452
466
*/
467
+ @ CanIgnoreReturnValue
453
468
public GsonBuilder addSerializationExclusionStrategy (ExclusionStrategy strategy ) {
454
469
Objects .requireNonNull (strategy );
455
470
excluder = excluder .withExclusionStrategy (strategy , true , false );
@@ -471,6 +486,7 @@ public GsonBuilder addSerializationExclusionStrategy(ExclusionStrategy strategy)
471
486
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
472
487
* @since 1.7
473
488
*/
489
+ @ CanIgnoreReturnValue
474
490
public GsonBuilder addDeserializationExclusionStrategy (ExclusionStrategy strategy ) {
475
491
Objects .requireNonNull (strategy );
476
492
excluder = excluder .withExclusionStrategy (strategy , false , true );
@@ -486,6 +502,7 @@ public GsonBuilder addDeserializationExclusionStrategy(ExclusionStrategy strateg
486
502
*
487
503
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
488
504
*/
505
+ @ CanIgnoreReturnValue
489
506
public GsonBuilder setPrettyPrinting () {
490
507
return setPrettyPrinting (FormattingStyle .DEFAULT );
491
508
}
@@ -500,6 +517,7 @@ public GsonBuilder setPrettyPrinting() {
500
517
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
501
518
* @since $next-version$
502
519
*/
520
+ @ CanIgnoreReturnValue
503
521
public GsonBuilder setPrettyPrinting (FormattingStyle formattingStyle ) {
504
522
this .formattingStyle = formattingStyle ;
505
523
return this ;
@@ -515,6 +533,7 @@ public GsonBuilder setPrettyPrinting(FormattingStyle formattingStyle) {
515
533
* @see JsonReader#setLenient(boolean)
516
534
* @see JsonWriter#setLenient(boolean)
517
535
*/
536
+ @ CanIgnoreReturnValue
518
537
public GsonBuilder setLenient () {
519
538
lenient = true ;
520
539
return this ;
@@ -527,6 +546,7 @@ public GsonBuilder setLenient() {
527
546
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
528
547
* @since 1.3
529
548
*/
549
+ @ CanIgnoreReturnValue
530
550
public GsonBuilder disableHtmlEscaping () {
531
551
this .escapeHtmlChars = false ;
532
552
return this ;
@@ -548,6 +568,7 @@ public GsonBuilder disableHtmlEscaping() {
548
568
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
549
569
* @since 1.2
550
570
*/
571
+ @ CanIgnoreReturnValue
551
572
public GsonBuilder setDateFormat (String pattern ) {
552
573
// TODO(Joel): Make this fail fast if it is an invalid date format
553
574
this .datePattern = pattern ;
@@ -568,6 +589,7 @@ public GsonBuilder setDateFormat(String pattern) {
568
589
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
569
590
* @since 1.2
570
591
*/
592
+ @ CanIgnoreReturnValue
571
593
public GsonBuilder setDateFormat (int style ) {
572
594
this .dateStyle = style ;
573
595
this .datePattern = null ;
@@ -589,6 +611,7 @@ public GsonBuilder setDateFormat(int style) {
589
611
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
590
612
* @since 1.2
591
613
*/
614
+ @ CanIgnoreReturnValue
592
615
public GsonBuilder setDateFormat (int dateStyle , int timeStyle ) {
593
616
this .dateStyle = dateStyle ;
594
617
this .timeStyle = timeStyle ;
@@ -618,6 +641,7 @@ public GsonBuilder setDateFormat(int dateStyle, int timeStyle) {
618
641
* {@link InstanceCreator}, {@link JsonSerializer}, and a {@link JsonDeserializer} interfaces.
619
642
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
620
643
*/
644
+ @ CanIgnoreReturnValue
621
645
public GsonBuilder registerTypeAdapter (Type type , Object typeAdapter ) {
622
646
Objects .requireNonNull (type );
623
647
$Gson$Preconditions .checkArgument (typeAdapter instanceof JsonSerializer <?>
@@ -651,6 +675,7 @@ public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
651
675
*
652
676
* @since 2.1
653
677
*/
678
+ @ CanIgnoreReturnValue
654
679
public GsonBuilder registerTypeAdapterFactory (TypeAdapterFactory factory ) {
655
680
Objects .requireNonNull (factory );
656
681
factories .add (factory );
@@ -671,6 +696,7 @@ public GsonBuilder registerTypeAdapterFactory(TypeAdapterFactory factory) {
671
696
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
672
697
* @since 1.7
673
698
*/
699
+ @ CanIgnoreReturnValue
674
700
public GsonBuilder registerTypeHierarchyAdapter (Class <?> baseType , Object typeAdapter ) {
675
701
Objects .requireNonNull (baseType );
676
702
$Gson$Preconditions .checkArgument (typeAdapter instanceof JsonSerializer <?>
@@ -707,6 +733,7 @@ public GsonBuilder registerTypeHierarchyAdapter(Class<?> baseType, Object typeAd
707
733
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
708
734
* @since 1.3
709
735
*/
736
+ @ CanIgnoreReturnValue
710
737
public GsonBuilder serializeSpecialFloatingPointValues () {
711
738
this .serializeSpecialFloatingPointValues = true ;
712
739
return this ;
@@ -728,6 +755,7 @@ public GsonBuilder serializeSpecialFloatingPointValues() {
728
755
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
729
756
* @since 2.9.0
730
757
*/
758
+ @ CanIgnoreReturnValue
731
759
public GsonBuilder disableJdkUnsafe () {
732
760
this .useJdkUnsafe = false ;
733
761
return this ;
@@ -753,6 +781,7 @@ public GsonBuilder disableJdkUnsafe() {
753
781
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
754
782
* @since 2.9.1
755
783
*/
784
+ @ CanIgnoreReturnValue
756
785
public GsonBuilder addReflectionAccessFilter (ReflectionAccessFilter filter ) {
757
786
Objects .requireNonNull (filter );
758
787
reflectionFilters .addFirst (filter );
0 commit comments