From 536325bc7524e9ba7c142eb13adc85fe272a28de Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 11 Feb 2013 09:18:57 -0800 Subject: [PATCH] Make HierarchicalUriComponents Serializable Issue: SPR-10266 --- .../web/util/HierarchicalUriComponents.java | 3 ++- .../web/util/UriComponentsTests.java | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java b/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java index 103784e9c2..720ca4fad7 100644 --- a/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java +++ b/spring-web/src/main/java/org/springframework/web/util/HierarchicalUriComponents.java @@ -17,6 +17,7 @@ package org.springframework.web.util; import java.io.ByteArrayOutputStream; +import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; @@ -615,7 +616,7 @@ final class HierarchicalUriComponents extends UriComponents { /** * Defines the contract for path (segments). */ - interface PathComponent { + interface PathComponent extends Serializable { String getPath(); diff --git a/spring-web/src/test/java/org/springframework/web/util/UriComponentsTests.java b/spring-web/src/test/java/org/springframework/web/util/UriComponentsTests.java index c9f8d60917..7fd5ccffd6 100644 --- a/spring-web/src/test/java/org/springframework/web/util/UriComponentsTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/UriComponentsTests.java @@ -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())); + } + }