aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--value/src/it/functional/src/test/java/com/google/auto/value/AutoAnnotationTest.java9
-rw-r--r--value/src/main/java/com/google/auto/value/processor/autoannotation.vm3
-rw-r--r--value/src/test/java/com/google/auto/value/processor/AutoAnnotationCompilationTest.java20
3 files changed, 25 insertions, 7 deletions
diff --git a/value/src/it/functional/src/test/java/com/google/auto/value/AutoAnnotationTest.java b/value/src/it/functional/src/test/java/com/google/auto/value/AutoAnnotationTest.java
index ca1ef6b9..af0b2da9 100644
--- a/value/src/it/functional/src/test/java/com/google/auto/value/AutoAnnotationTest.java
+++ b/value/src/it/functional/src/test/java/com/google/auto/value/AutoAnnotationTest.java
@@ -26,6 +26,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.primitives.Ints;
import com.google.common.testing.EqualsTester;
+import com.google.common.testing.SerializableTester;
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -406,6 +407,14 @@ public class AutoAnnotationTest {
.testEquals();
}
+ @Test
+ public void testSerialization() {
+ Annotation[] instances = {EVERYTHING_FROM_AUTO, EVERYTHING_FROM_AUTO_COLLECTIONS};
+ for (Annotation instance : instances) {
+ SerializableTester.reserializeAndAssert(instance);
+ }
+ }
+
public static class IntList extends ArrayList<Integer> {
IntList(Collection<Integer> c) {
super(c);
diff --git a/value/src/main/java/com/google/auto/value/processor/autoannotation.vm b/value/src/main/java/com/google/auto/value/processor/autoannotation.vm
index a953edab..5d697d22 100644
--- a/value/src/main/java/com/google/auto/value/processor/autoannotation.vm
+++ b/value/src/main/java/com/google/auto/value/processor/autoannotation.vm
@@ -45,7 +45,8 @@ package $pkg;
#else
// Generated by com.google.auto.value.processor.AutoAnnotationProcessor
#end
-final class $className implements $annotationName {
+final class $className implements $annotationName, `java.io.Serializable` {
+ private static final long serialVersionUID = 1L;
## Fields
diff --git a/value/src/test/java/com/google/auto/value/processor/AutoAnnotationCompilationTest.java b/value/src/test/java/com/google/auto/value/processor/AutoAnnotationCompilationTest.java
index b8a36eac..f30f519d 100644
--- a/value/src/test/java/com/google/auto/value/processor/AutoAnnotationCompilationTest.java
+++ b/value/src/test/java/com/google/auto/value/processor/AutoAnnotationCompilationTest.java
@@ -74,11 +74,13 @@ public class AutoAnnotationCompilationTest {
"",
"import com.example.annotations.MyAnnotation;",
"import com.example.enums.MyEnum;",
+ "import java.io.Serializable;",
GeneratedImport.importGeneratedAnnotationType(),
"",
"@Generated(\"" + AutoAnnotationProcessor.class.getName() + "\")",
"final class AutoAnnotation_AnnotationFactory_newMyAnnotation",
- " implements MyAnnotation {",
+ " implements MyAnnotation, Serializable {",
+ " private static final long serialVersionUID = 1L;",
" private final MyEnum value;",
" private static final int defaultedValue = 23;",
"",
@@ -157,11 +159,13 @@ public class AutoAnnotationCompilationTest {
JavaFileObject expectedOutput =
JavaFileObjects.forSourceLines(
"AutoAnnotation_AnnotationFactory_newMyAnnotation",
+ "import java.io.Serializable;",
GeneratedImport.importGeneratedAnnotationType(),
"",
"@Generated(\"" + AutoAnnotationProcessor.class.getName() + "\")",
"final class AutoAnnotation_AnnotationFactory_newMyAnnotation",
- " implements MyAnnotation {",
+ " implements MyAnnotation, Serializable {",
+ " private static final long serialVersionUID = 1L;",
" AutoAnnotation_AnnotationFactory_newMyAnnotation() {",
" }",
"",
@@ -237,12 +241,14 @@ public class AutoAnnotationCompilationTest {
"package com.example.factories;",
"",
"import com.example.annotations.MyAnnotation;",
+ "import java.io.Serializable",
"import java.util.Arrays;",
GeneratedImport.importGeneratedAnnotationType(),
"",
"@Generated(\"" + AutoAnnotationProcessor.class.getName() + "\")",
- "final class AutoAnnotation_AnnotationFactory_newMyAnnotation implements MyAnnotation"
- + " {",
+ "final class AutoAnnotation_AnnotationFactory_newMyAnnotation implements MyAnnotation,"
+ + " Serializable {",
+ " private static final long serialVersionUID = 1L;",
" private final int[] value;",
"",
" AutoAnnotation_AnnotationFactory_newMyAnnotation(int[] value) {",
@@ -343,6 +349,7 @@ public class AutoAnnotationCompilationTest {
"",
"import com.example.annotations.MyAnnotation;",
"import com.example.enums.MyEnum;",
+ "import java.io.Serializable;",
"import java.util.Arrays;",
"import java.util.Collection;",
"import java.util.List;",
@@ -350,8 +357,9 @@ public class AutoAnnotationCompilationTest {
GeneratedImport.importGeneratedAnnotationType(),
"",
"@Generated(\"" + AutoAnnotationProcessor.class.getName() + "\")",
- "final class AutoAnnotation_AnnotationFactory_newMyAnnotation implements MyAnnotation"
- + " {",
+ "final class AutoAnnotation_AnnotationFactory_newMyAnnotation implements MyAnnotation,"
+ + " Serializable {",
+ " private static final long serialVersionUID = 1L;",
" private final int[] value;",
" private final MyEnum[] enums;",
"",