Skip to content
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

Support for HATEOAS-Links in Json-Views #359

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0fdf663
Allow for links property to be rendered to JSON when filtered by prov…
Jun 12, 2015
376740f
Explain bundlor to eclipse.
Jun 13, 2015
d2f2834
Revert "Allow for links property to be rendered to JSON when filtered…
Jun 13, 2015
e1623fb
Allow for links property to be rendered to JSON
Jun 13, 2015
8da55e1
Missing import added (merge problem).
Jun 14, 2015
af813ca
Support views for Resource and Resources as well.
Jun 17, 2015
57d2be0
Move marker interface to separate module.
Jun 19, 2015
d4bba8f
general contribution clean-up
Jun 19, 2015
2222a40
#353 - Dependency upgrades.
odrotbohm Aug 4, 2015
c73dde6
#364 - Add missing parentheses in reference documentation.
aaguilera Jul 13, 2015
2cec998
#247 - Added HAL_JSON_VALUE in MediaTypes.
pnowy Apr 4, 2015
d0691ab
#353 - Release version 0.18.0.RELEASE.
spring-builds Aug 4, 2015
01d2489
#353 - Prepare next development iteration.
spring-builds Aug 4, 2015
e6e23b4
#353 - After release cleanups.
odrotbohm Aug 4, 2015
dcf692c
#375 - Fixed is-empty evaluation for TrueOnlyBooleanSerializer on Jac…
odrotbohm Aug 11, 2015
d8cc666
#363 - Extended DefaultCurieProvider to be able to configure multiple…
odrotbohm Aug 13, 2015
d77a4b6
#320 - Overhaul in curie rendering.
odrotbohm Aug 19, 2015
71ec26f
#378 - HAL links get title attributes rendered resolved through a res…
odrotbohm Aug 19, 2015
790e10b
#376 - Compile against latest JAX-RS API.
wilkinsona Aug 12, 2015
1ecedaa
#379 - Added test case that shows AbstractJackson2HttpMessageConverte…
odrotbohm Aug 12, 2015
d4ac71a
#379 - Updated changelog.
odrotbohm Sep 1, 2015
e538dd3
#379 - Release version 0.19.0.RELEASE.
spring-builds Sep 1, 2015
b41402f
#379 - Prepare next development iteration.
spring-builds Sep 1, 2015
9d35670
#380 - Renamed *Tests classes to *Test to make sure the Maven build r…
odrotbohm Sep 2, 2015
a019eda
#381 - Upgraded Spring 4.2 build profile to Spring 4.2.1.RELEASE.
odrotbohm Sep 2, 2015
dd4ec34
#337 - Fixed potential double-encoding in Traverson.
Aug 31, 2015
4e1e5ed
#383 - Reinstantiated Jackson 2.4 compatibility.
odrotbohm Sep 3, 2015
54c8557
Merge branch 'master' of https://github.com/tinne/spring-hateoas
Sep 5, 2015
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
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ jdk:
env:
matrix:
- PROFILE=non-existant
- PROFILE=spring41
- PROFILE=spring41-next
- PROFILE=spring42
- PROFILE=spring42-next
cache:
directories:
- $HOME/.m2
sudo: false
install: true
script: "mvn clean dependency:list test -P${PROFILE} -Dsort"
script: "mvn clean dependency:list test -P${PROFILE} -Dsort"
96 changes: 51 additions & 45 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<version>0.18.0.BUILD-SNAPSHOT</version>
<version>0.20.0.BUILD-SNAPSHOT</version>

<name>Spring HATEOAS</name>
<url>http://github.com/SpringSource/spring-hateoas</url>
Expand Down Expand Up @@ -58,12 +58,12 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.0.9.RELEASE</spring.version>
<spring.version>4.1.7.RELEASE</spring.version>
<logback.version>1.1.3</logback.version>
<jackson.version>2.5.4</jackson.version>
<jaxrs.version>1.0</jaxrs.version>
<minidevjson.version>2.1.1</minidevjson.version>
<jsonpath.version>0.9.1</jsonpath.version>
<jaxrs.version>2.0.1</jaxrs.version>
<minidevjson.version>2.2</minidevjson.version>
<jsonpath.version>2.0.0</jsonpath.version>
<slf4j.version>1.7.12</slf4j.version>
<evo.version>1.2.1</evo.version>
<bundlor.failOnWarnings>true</bundlor.failOnWarnings>
Expand All @@ -73,42 +73,18 @@
<profiles>

<profile>
<id>spring40-next</id>
<id>spring42</id>
<properties>
<spring.version>4.0.10.BUILD-SNAPSHOT</spring.version>
<spring.version>4.2.1.RELEASE</spring.version>
<jackson.version>2.6.1</jackson.version>
</properties>
<repositories>
<repository>
<id>spring-libs-snapshot</id>
<url>http://repo.spring.io/libs-snapshot</url>
</repository>
</repositories>
</profile>

<profile>
<id>spring41</id>
<properties>
<spring.version>4.1.6.RELEASE</spring.version>
</properties>
</profile>

<profile>
<id>spring41-next</id>
<properties>
<spring.version>4.1.6.BUILD-SNAPSHOT</spring.version>
</properties>
<repositories>
<repository>
<id>spring-libs-snapshot</id>
<url>http://repo.spring.io/libs-snapshot</url>
</repository>
</repositories>
</profile>

<profile>
<id>spring42-next</id>
<properties>
<spring.version>4.2.0.BUILD-SNAPSHOT</spring.version>
<spring.version>4.2.2.BUILD-SNAPSHOT</spring.version>
<jackson.version>2.6.1</jackson.version>
</properties>
<repositories>
<repository>
Expand Down Expand Up @@ -167,7 +143,7 @@
<dependency>
<groupId>org.springframework.data.build</groupId>
<artifactId>spring-data-build-resources</artifactId>
<version>1.6.0.RELEASE</version>
<version>1.6.2.RELEASE</version>
<scope>provided</scope>
<type>zip</type>
</dependency>
Expand Down Expand Up @@ -223,12 +199,12 @@
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.2</version>
<version>1.5.2.1</version>
<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj-pdf</artifactId>
<version>1.5.0-alpha.6</version>
<version>1.5.0-alpha.8</version>
</dependency>
<dependency>
<groupId>org.asciidoctor</groupId>
Expand Down Expand Up @@ -355,7 +331,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.4</version>
<version>2.5.5</version>
<executions>
<execution>
<id>static</id>
Expand Down Expand Up @@ -473,7 +449,7 @@

<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${jaxrs.version}</version>
<optional>true</optional>
</dependency>
Expand All @@ -495,7 +471,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.4</version>
<version>1.16.4</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -529,7 +505,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.12</version>
<scope>test</scope>
</dependency>

Expand All @@ -543,21 +519,21 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<version>1.10.19</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
<version>2.8.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.5</version>
<version>1.6</version>
<scope>test</scope>
</dependency>

Expand All @@ -580,6 +556,36 @@
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>com.springsource.bundlor</groupId>
<artifactId>com.springsource.bundlor.maven</artifactId>
<versionRange>[1.0,2.0)</versionRange>
<goals>
<goal>bundlor</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>

<extensions>
<extension>
Expand Down Expand Up @@ -652,7 +658,7 @@
<additionalparam>-Xdoclint:none</additionalparam>
<stylesheetfile>${shared.resources}/javadoc/spring-javadoc.css</stylesheetfile>
<links>
<link>http://static.springframework.org/spring/docs/3.2.x/javadoc-api</link>
<link>http://static.springframework.org/spring/docs/4.1.x/javadoc-api</link>
<link>http://docs.oracle.com/javase/6/docs/api</link>
</links>
</configuration>
Expand Down
2 changes: 1 addition & 1 deletion src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ You can also easily access links contained in that resource:
[source, java]
----
Link selfLink = new Link("http://myhost/people");
assertThat(resource.getId(), is(selfLink);
assertThat(resource.getId(), is(selfLink));
assertThat(resource.getLink(Link.SELF), is(selfLink));
----
[[fundamentals.obtaining-links]]
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/springframework/hateoas/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonView;

/**
* Value object for links.
Expand Down Expand Up @@ -104,6 +105,7 @@ protected Link() {
*
* @return
*/
@JsonView(ResourcesLinksVisible.class)
public String getHref() {
return href;
}
Expand All @@ -113,6 +115,7 @@ public String getHref() {
*
* @return
*/
@JsonView(ResourcesLinksVisible.class)
public String getRel() {
return rel;
}
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/springframework/hateoas/MediaTypes.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,8 +21,17 @@
* Constants for well-known hypermedia types.
*
* @author Oliver Gierke
* @author Przemek Nowak
*/
public class MediaTypes {

public static final MediaType HAL_JSON = MediaType.valueOf("application/hal+json");
/**
* A String equivalent of {@link MediaTypes#HAL_JSON}.
*/
public static final String HAL_JSON_VALUE = "application/hal+json";

/**
* Public constant media type for {@code application/hal+json}.
*/
public static final MediaType HAL_JSON = MediaType.valueOf(HAL_JSON_VALUE);
}
2 changes: 2 additions & 0 deletions src/main/java/org/springframework/hateoas/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.util.Assert;

import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.annotation.JsonView;

/**
* A simple {@link Resource} wrapping a domain object and adding links to it.
Expand Down Expand Up @@ -73,6 +74,7 @@ public Resource(T content, Iterable<Link> links) {
*/
@JsonUnwrapped
@XmlAnyElement
@JsonView(ResourcesLinksVisible.class)
public T getContent() {
return content;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/springframework/hateoas/ResourceSupport.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;

/**
* Base class for DTOs to collect links.
Expand Down Expand Up @@ -105,6 +106,7 @@ public boolean hasLink(String rel) {
*/
@XmlElement(name = "link", namespace = Link.ATOM_NAMESPACE)
@JsonProperty("links")
@JsonView(ResourcesLinksVisible.class)
public List<Link> getLinks() {
return links;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/springframework/hateoas/Resources.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.util.Assert;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;

/**
* General helper to easily create a wrapper for a collection of entities.
Expand Down Expand Up @@ -101,6 +102,7 @@ public static <T extends Resource<S>, S> Resources<T> wrap(Iterable<S> content)
@XmlAnyElement
@XmlElementWrapper
@JsonProperty("content")
@JsonView(ResourcesLinksVisible.class)
public Collection<T> getContent() {
return Collections.unmodifiableCollection(content);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.hateoas;

/**
* Parent interface to mark {@link Resource}(s) beans that {@link Link}s and Resource
* {@code content} are part of a JSON view.
*
* Usage: subinterface and mark all view relevant properties of your bean
* {@code @JSonView(SubInterface.class)}. Then serialize bean of {@code new Resource<>(bean)} to
* JSON. Your ({@code content} with) relevant properties and all associated {@code labels} will be
* visible.
*
* @see com.fasterxml.jackson.annotation.JsonView
* @since 0.18.0
*
* @author Karsten Tinnefeld
*/
public interface ResourcesLinksVisible {}
Loading