diff --git a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index 77a4c59183..9a3b2ad413 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -16,6 +16,7 @@ package org.springframework.core.convert; +import java.io.Serializable; import java.lang.annotation.Annotation; import java.lang.reflect.Array; import java.lang.reflect.Field; @@ -38,7 +39,10 @@ import org.springframework.util.ObjectUtils; * @author Sam Brannen * @since 3.0 */ -public class TypeDescriptor { +public class TypeDescriptor implements Serializable { + + private static final long serialVersionUID = 1L; + static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0]; diff --git a/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java b/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java index 6597ab46a7..7af9d19f87 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java @@ -16,6 +16,10 @@ package org.springframework.core.convert; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -32,6 +36,7 @@ import java.util.Map; import org.junit.Test; import org.springframework.core.MethodParameter; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; /** @@ -870,4 +875,16 @@ public class TypeDescriptorTests { public void createNullArray() throws Exception { assertNull(TypeDescriptor.array(null)); } + + @Test + public void serializable() throws Exception { + TypeDescriptor typeDescriptor = TypeDescriptor.forObject(""); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ObjectOutputStream outputStream = new ObjectOutputStream(out); + outputStream.writeObject(typeDescriptor); + ObjectInputStream inputStream = new ObjectInputStream(new ByteArrayInputStream( + out.toByteArray())); + TypeDescriptor readObject = (TypeDescriptor) inputStream.readObject(); + assertThat(readObject, equalTo(typeDescriptor)); + } }