#172 - Made types contained in Link implement Serializable.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.hateoas;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -26,7 +27,9 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public final class TemplateVariable {
|
||||
public final class TemplateVariable implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2731446749851863774L;
|
||||
|
||||
private final String name;
|
||||
private final TemplateVariable.VariableType type;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.hateoas;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -29,9 +30,10 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public final class TemplateVariables implements Iterable<TemplateVariable> {
|
||||
public final class TemplateVariables implements Iterable<TemplateVariable>, Serializable {
|
||||
|
||||
public static TemplateVariables NONE = new TemplateVariables();
|
||||
private static final long serialVersionUID = -7736592281223783079L;
|
||||
|
||||
private final List<TemplateVariable> variables;
|
||||
|
||||
@@ -112,6 +114,7 @@ public final class TemplateVariables implements Iterable<TemplateVariable> {
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
if (variables.isEmpty()) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.hateoas;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -36,9 +37,10 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
* @see http://tools.ietf.org/html/rfc6570
|
||||
* @since 0.9
|
||||
*/
|
||||
public class UriTemplate implements Iterable<TemplateVariable> {
|
||||
public class UriTemplate implements Iterable<TemplateVariable>, Serializable {
|
||||
|
||||
private static final Pattern VARIABLE_REGEX = Pattern.compile("\\{([\\?\\&#/]?)([\\w\\,]+)\\}");
|
||||
private static final long serialVersionUID = -1007874653930162262L;
|
||||
|
||||
private final TemplateVariables variables;;
|
||||
private String baseUri;
|
||||
|
||||
@@ -18,6 +18,10 @@ package org.springframework.hateoas;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import org.apache.commons.io.output.ByteArrayOutputStream;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@@ -146,4 +150,17 @@ public class LinkUnitTest {
|
||||
assertThat(link.isTemplated(), is(false));
|
||||
assertThat(link.getVariableNames(), hasSize(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #172
|
||||
*/
|
||||
@Test
|
||||
public void serializesCorrectly() throws IOException {
|
||||
|
||||
Link link = new Link("http://foobar{?foo,bar}");
|
||||
|
||||
ObjectOutputStream stream = new ObjectOutputStream(new ByteArrayOutputStream());
|
||||
stream.writeObject(link);
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user