Make HierarchicalUriComponents Serializable

Issue: SPR-10266
This commit is contained in:
Phillip Webb
2013-02-11 09:18:57 -08:00
parent 6fc0790c5f
commit 536325bc75
2 changed files with 19 additions and 1 deletions

View File

@@ -16,11 +16,16 @@
package org.springframework.web.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.*;
/** @author Arjen Poutsma */
@@ -75,4 +80,16 @@ public class UriComponentsTests {
assertEquals("http://example.com/bar", uriComponents.normalize().toString());
}
@Test
public void serializable() throws Exception {
UriComponents uriComponents = UriComponentsBuilder.fromUriString(
"http://example.com").path("/{foo}").query("bar={baz}").build();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(uriComponents);
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
UriComponents readObject = (UriComponents) ois.readObject();
assertThat(uriComponents.toString(), equalTo(readObject.toString()));
}
}