Skip to content

Commit

Permalink
Make HierarchicalUriComponents Serializable
Browse files Browse the repository at this point in the history
Issue: SPR-10266
  • Loading branch information
philwebb committed Feb 11, 2013
1 parent 6fc0790 commit 536325b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -615,7 +616,7 @@ protected boolean isPchar(int c) {
/**
* Defines the contract for path (segments).
*/
interface PathComponent {
interface PathComponent extends Serializable {

String getPath();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -75,4 +80,16 @@ public void normalize() {
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()));
}

}

0 comments on commit 536325b

Please sign in to comment.