Skip to content

Commit 7eb2d47

Browse files
eamonnmcmanusGoogle Java Core Libraries
authored andcommitted
Make @AutoAnnotation instances serializable.
RELNOTES=`@AutoAnnotation` instances are now serializable. PiperOrigin-RevId: 331666372
1 parent cd3fb8d commit 7eb2d47

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

value/src/it/functional/src/test/java/com/google/auto/value/AutoAnnotationTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.common.collect.ImmutableSortedSet;
2727
import com.google.common.primitives.Ints;
2828
import com.google.common.testing.EqualsTester;
29+
import com.google.common.testing.SerializableTester;
2930
import java.lang.annotation.Annotation;
3031
import java.lang.annotation.Retention;
3132
import java.lang.annotation.RetentionPolicy;
@@ -406,6 +407,14 @@ public void testEqualsAndHashCode() {
406407
.testEquals();
407408
}
408409

410+
@Test
411+
public void testSerialization() {
412+
Annotation[] instances = {EVERYTHING_FROM_AUTO, EVERYTHING_FROM_AUTO_COLLECTIONS};
413+
for (Annotation instance : instances) {
414+
SerializableTester.reserializeAndAssert(instance);
415+
}
416+
}
417+
409418
public static class IntList extends ArrayList<Integer> {
410419
IntList(Collection<Integer> c) {
411420
super(c);

value/src/main/java/com/google/auto/value/processor/autoannotation.vm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ package $pkg;
4545
#else
4646
// Generated by com.google.auto.value.processor.AutoAnnotationProcessor
4747
#end
48-
final class $className implements $annotationName {
48+
final class $className implements $annotationName, `java.io.Serializable` {
49+
private static final long serialVersionUID = 1L;
4950

5051
## Fields
5152

value/src/test/java/com/google/auto/value/processor/AutoAnnotationCompilationTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ public void testSimple() {
7474
"",
7575
"import com.example.annotations.MyAnnotation;",
7676
"import com.example.enums.MyEnum;",
77+
"import java.io.Serializable;",
7778
GeneratedImport.importGeneratedAnnotationType(),
7879
"",
7980
"@Generated(\"" + AutoAnnotationProcessor.class.getName() + "\")",
8081
"final class AutoAnnotation_AnnotationFactory_newMyAnnotation",
81-
" implements MyAnnotation {",
82+
" implements MyAnnotation, Serializable {",
83+
" private static final long serialVersionUID = 1L;",
8284
" private final MyEnum value;",
8385
" private static final int defaultedValue = 23;",
8486
"",
@@ -157,11 +159,13 @@ public void testEmptyPackage() {
157159
JavaFileObject expectedOutput =
158160
JavaFileObjects.forSourceLines(
159161
"AutoAnnotation_AnnotationFactory_newMyAnnotation",
162+
"import java.io.Serializable;",
160163
GeneratedImport.importGeneratedAnnotationType(),
161164
"",
162165
"@Generated(\"" + AutoAnnotationProcessor.class.getName() + "\")",
163166
"final class AutoAnnotation_AnnotationFactory_newMyAnnotation",
164-
" implements MyAnnotation {",
167+
" implements MyAnnotation, Serializable {",
168+
" private static final long serialVersionUID = 1L;",
165169
" AutoAnnotation_AnnotationFactory_newMyAnnotation() {",
166170
" }",
167171
"",
@@ -237,12 +241,14 @@ public void testGwtSimple() {
237241
"package com.example.factories;",
238242
"",
239243
"import com.example.annotations.MyAnnotation;",
244+
"import java.io.Serializable",
240245
"import java.util.Arrays;",
241246
GeneratedImport.importGeneratedAnnotationType(),
242247
"",
243248
"@Generated(\"" + AutoAnnotationProcessor.class.getName() + "\")",
244-
"final class AutoAnnotation_AnnotationFactory_newMyAnnotation implements MyAnnotation"
245-
+ " {",
249+
"final class AutoAnnotation_AnnotationFactory_newMyAnnotation implements MyAnnotation,"
250+
+ " Serializable {",
251+
" private static final long serialVersionUID = 1L;",
246252
" private final int[] value;",
247253
"",
248254
" AutoAnnotation_AnnotationFactory_newMyAnnotation(int[] value) {",
@@ -343,15 +349,17 @@ public void testCollectionsForArrays() {
343349
"",
344350
"import com.example.annotations.MyAnnotation;",
345351
"import com.example.enums.MyEnum;",
352+
"import java.io.Serializable;",
346353
"import java.util.Arrays;",
347354
"import java.util.Collection;",
348355
"import java.util.List;",
349356
"import java.util.Set;",
350357
GeneratedImport.importGeneratedAnnotationType(),
351358
"",
352359
"@Generated(\"" + AutoAnnotationProcessor.class.getName() + "\")",
353-
"final class AutoAnnotation_AnnotationFactory_newMyAnnotation implements MyAnnotation"
354-
+ " {",
360+
"final class AutoAnnotation_AnnotationFactory_newMyAnnotation implements MyAnnotation,"
361+
+ " Serializable {",
362+
" private static final long serialVersionUID = 1L;",
355363
" private final int[] value;",
356364
" private final MyEnum[] enums;",
357365
"",

0 commit comments

Comments
 (0)