提交 9eb596a7 编写于 作者: P Phillip Webb

Make TypeDescriptor serializable

Issue: SPR-10631
上级 9939c480
......@@ -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];
......
......@@ -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));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册