Skip to content

Commit 9eb596a

Browse files
committed
Make TypeDescriptor serializable
Issue: SPR-10631
1 parent 9939c48 commit 9eb596a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.core.convert;
1818

19+
import java.io.Serializable;
1920
import java.lang.annotation.Annotation;
2021
import java.lang.reflect.Array;
2122
import java.lang.reflect.Field;
@@ -38,7 +39,10 @@
3839
* @author Sam Brannen
3940
* @since 3.0
4041
*/
41-
public class TypeDescriptor {
42+
public class TypeDescriptor implements Serializable {
43+
44+
private static final long serialVersionUID = 1L;
45+
4246

4347
static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
4448

spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
package org.springframework.core.convert;
1818

19+
import java.io.ByteArrayInputStream;
20+
import java.io.ByteArrayOutputStream;
21+
import java.io.ObjectInputStream;
22+
import java.io.ObjectOutputStream;
1923
import java.lang.annotation.ElementType;
2024
import java.lang.annotation.Retention;
2125
import java.lang.annotation.RetentionPolicy;
@@ -32,6 +36,7 @@
3236
import org.junit.Test;
3337
import org.springframework.core.MethodParameter;
3438

39+
import static org.hamcrest.Matchers.*;
3540
import static org.junit.Assert.*;
3641

3742
/**
@@ -870,4 +875,16 @@ public void createStringArray() throws Exception {
870875
public void createNullArray() throws Exception {
871876
assertNull(TypeDescriptor.array(null));
872877
}
878+
879+
@Test
880+
public void serializable() throws Exception {
881+
TypeDescriptor typeDescriptor = TypeDescriptor.forObject("");
882+
ByteArrayOutputStream out = new ByteArrayOutputStream();
883+
ObjectOutputStream outputStream = new ObjectOutputStream(out);
884+
outputStream.writeObject(typeDescriptor);
885+
ObjectInputStream inputStream = new ObjectInputStream(new ByteArrayInputStream(
886+
out.toByteArray()));
887+
TypeDescriptor readObject = (TypeDescriptor) inputStream.readObject();
888+
assertThat(readObject, equalTo(typeDescriptor));
889+
}
873890
}

0 commit comments

Comments
 (0)