Skip to content

Allow Strings and URIs for the @Link annotation when serializing #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.openapitools.jackson.dataformat.hal.annotation.EmbeddedResource;
import io.openapitools.jackson.dataformat.hal.annotation.Link;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -127,6 +128,10 @@ public FilteredProperties(Object bean, SerializerProvider provider,
addLinks(relation, (Collection<HALLink>) prop.get(bean), curie);
} else if (value instanceof HALLink) {
addLink(relation, (HALLink) prop.get(bean), curie);
} else if (value instanceof String) {
addLink(relation, new HALLink.Builder((String) value).build(), curie);
} else if (value instanceof URI) {
addLink(relation, new HALLink.Builder((URI) value).build(), curie);
}

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -28,7 +29,9 @@ public void testSerialization() throws Exception {
+ "\"child\":[{\"href\":\"/top/1/child/1\"},{\"href\":\"/top/1/child/2\"}],"
+ "\"empty:list\":[],"
+ "\"self\":{\"href\":\"/top/1\"},"
+ "\"templated\":{\"href\":\"/uri/{id}\",\"templated\":true}"
+ "\"stringLink\":{\"href\":\"http://something.com\",\"templated\":false},"
+ "\"templated\":{\"href\":\"/uri/{id}\",\"templated\":true},"
+ "\"uriLink\":{\"href\":\"http://something.else.com\"}"
+ "},"
+ "\"_embedded\":{"
+ "\"child\":["
Expand All @@ -50,6 +53,12 @@ public static class TopResource {
@Link("child")
public HALLink childLink = new HALLink.Builder(URI.create("/should/be/overridden")).build();

@Link
public String stringLink = "http://something.com";

@Link
public URI uriLink = new URI("http://something.else.com");

@Link
public HALLink templated = new HALLink.Builder("/uri/{id}").build();

Expand All @@ -75,6 +84,9 @@ public static class TopResource {

@EmbeddedResource
public String nullString = null;

public TopResource() throws URISyntaxException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add the default constructor?

}
}

@Resource
Expand Down