Browse Source

Make TypeDescriptor serializable

Issue: SPR-10631
pull/320/merge
Phillip Webb 11 years ago
parent
commit
9eb596a7e5
  1. 6
      spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java
  2. 17
      spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java

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

@ -16,6 +16,7 @@ @@ -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; @@ -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];

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

@ -16,6 +16,10 @@ @@ -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; @@ -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 { @@ -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));
}
}

Loading…
Cancel
Save