diff --git a/pom.xml b/pom.xml
index a76e3642..7ac76e40 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,7 +58,8 @@
3.1.2.RELEASE
- 1.9.10
+ 1.9.10
+ 2.1.1
1.0
true
@@ -100,7 +101,14 @@
org.codehaus.jackson
jackson-core-asl
- ${jackson.version}
+ ${jackson1.version}
+ true
+
+
+
+ com.fasterxml.jackson.core
+ jackson-annotations
+ ${jackson2.version}
true
@@ -114,7 +122,14 @@
org.codehaus.jackson
jackson-mapper-asl
- ${jackson.version}
+ ${jackson1.version}
+ test
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ ${jackson2.version}
test
diff --git a/src/main/java/org/springframework/hateoas/PagedResources.java b/src/main/java/org/springframework/hateoas/PagedResources.java
index 2a4a1231..6fab92f2 100644
--- a/src/main/java/org/springframework/hateoas/PagedResources.java
+++ b/src/main/java/org/springframework/hateoas/PagedResources.java
@@ -22,9 +22,6 @@ import java.util.Collection;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
-import org.codehaus.jackson.annotate.JsonAutoDetect;
-import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
-import org.codehaus.jackson.annotate.JsonProperty;
import org.springframework.util.Assert;
/**
@@ -33,10 +30,12 @@ import org.springframework.util.Assert;
* @author Oliver Gierke
*/
@XmlRootElement(name = "entities")
-@JsonAutoDetect(fieldVisibility = Visibility.ANY)
+@org.codehaus.jackson.annotate.JsonAutoDetect(fieldVisibility = org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.ANY)
+@com.fasterxml.jackson.annotation.JsonAutoDetect(fieldVisibility = com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY)
public class PagedResources extends Resources {
- @JsonProperty("page")
+ @org.codehaus.jackson.annotate.JsonProperty("page")
+ @com.fasterxml.jackson.annotation.JsonProperty("page")
private PageMetadata metadata;
/**
@@ -145,23 +144,28 @@ public class PagedResources extends Resources {
*
* @author Oliver Gierke
*/
- @JsonAutoDetect(fieldVisibility = Visibility.ANY)
+ @org.codehaus.jackson.annotate.JsonAutoDetect(fieldVisibility = org.codehaus.jackson.annotate.JsonAutoDetect.Visibility.ANY)
+ @com.fasterxml.jackson.annotation.JsonAutoDetect(fieldVisibility = com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.ANY)
public static class PageMetadata {
@XmlAttribute
- @JsonProperty
+ @org.codehaus.jackson.annotate.JsonProperty
+ @com.fasterxml.jackson.annotation.JsonProperty
private long size;
@XmlAttribute
- @JsonProperty
+ @org.codehaus.jackson.annotate.JsonProperty
+ @com.fasterxml.jackson.annotation.JsonProperty
private long totalElements;
@XmlAttribute
- @JsonProperty
+ @org.codehaus.jackson.annotate.JsonProperty
+ @com.fasterxml.jackson.annotation.JsonProperty
private long totalPages;
@XmlAttribute
- @JsonProperty
+ @org.codehaus.jackson.annotate.JsonProperty
+ @com.fasterxml.jackson.annotation.JsonProperty
private long number;
protected PageMetadata() {
diff --git a/src/main/java/org/springframework/hateoas/Resource.java b/src/main/java/org/springframework/hateoas/Resource.java
index d60814b2..82035261 100644
--- a/src/main/java/org/springframework/hateoas/Resource.java
+++ b/src/main/java/org/springframework/hateoas/Resource.java
@@ -19,7 +19,6 @@ import java.util.Arrays;
import javax.xml.bind.annotation.XmlRootElement;
-import org.codehaus.jackson.annotate.JsonUnwrapped;
import org.springframework.util.Assert;
/**
@@ -30,7 +29,8 @@ import org.springframework.util.Assert;
@XmlRootElement
public class Resource extends ResourceSupport {
- @JsonUnwrapped
+ @org.codehaus.jackson.annotate.JsonUnwrapped
+ @com.fasterxml.jackson.annotation.JsonUnwrapped
private final T content;
/**
diff --git a/src/main/java/org/springframework/hateoas/ResourceSupport.java b/src/main/java/org/springframework/hateoas/ResourceSupport.java
index 3641078d..c2cb23ff 100755
--- a/src/main/java/org/springframework/hateoas/ResourceSupport.java
+++ b/src/main/java/org/springframework/hateoas/ResourceSupport.java
@@ -21,8 +21,6 @@ import java.util.List;
import javax.xml.bind.annotation.XmlElement;
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.annotate.JsonProperty;
import org.springframework.util.Assert;
/**
@@ -33,7 +31,8 @@ import org.springframework.util.Assert;
public class ResourceSupport implements Identifiable {
@XmlElement(name = "link", namespace = Link.ATOM_NAMESPACE)
- @JsonProperty("links")
+ @org.codehaus.jackson.annotate.JsonProperty("links")
+ @com.fasterxml.jackson.annotation.JsonProperty("links")
private final List links;
public ResourceSupport() {
@@ -43,7 +42,8 @@ public class ResourceSupport implements Identifiable {
/**
* Returns the {@link Link} with a rel of {@link Link#REL_SELF}.
*/
- @JsonIgnore
+ @org.codehaus.jackson.annotate.JsonIgnore
+ @com.fasterxml.jackson.annotation.JsonIgnore
public Link getId() {
return getLink(Link.REL_SELF);
}
diff --git a/src/main/java/org/springframework/hateoas/Resources.java b/src/main/java/org/springframework/hateoas/Resources.java
index fb8b797a..16984493 100644
--- a/src/main/java/org/springframework/hateoas/Resources.java
+++ b/src/main/java/org/springframework/hateoas/Resources.java
@@ -25,7 +25,6 @@ import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
-import org.codehaus.jackson.annotate.JsonProperty;
import org.springframework.util.Assert;
/**
@@ -38,7 +37,8 @@ public class Resources extends ResourceSupport implements Iterable {
@XmlAnyElement
@XmlElementWrapper
- @JsonProperty("content")
+ @org.codehaus.jackson.annotate.JsonProperty("content")
+ @com.fasterxml.jackson.annotation.JsonProperty("content")
private final Collection content;
/**
diff --git a/src/test/java/org/springframework/hateoas/AbstractJackson2MarshallingIntegrationTests.java b/src/test/java/org/springframework/hateoas/AbstractJackson2MarshallingIntegrationTests.java
new file mode 100644
index 00000000..9b476b8f
--- /dev/null
+++ b/src/test/java/org/springframework/hateoas/AbstractJackson2MarshallingIntegrationTests.java
@@ -0,0 +1,34 @@
+package org.springframework.hateoas;
+
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.junit.Before;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * Base class to test objects against the Jackson 2.0 {@link ObjectMapper}.
+ *
+ * @author Oliver Gierke
+ * @author Jon Brisbin
+ */
+public abstract class AbstractJackson2MarshallingIntegrationTests {
+
+ ObjectMapper mapper;
+
+ @Before
+ public void setUp() {
+ mapper = new ObjectMapper();
+ }
+
+ protected String write(Object object) throws Exception {
+ Writer writer = new StringWriter();
+ mapper.writeValue(writer, object);
+ return writer.toString();
+ }
+
+ protected T read(String source, Class targetType) throws Exception {
+ return mapper.readValue(source, targetType);
+ }
+}
diff --git a/src/test/java/org/springframework/hateoas/Jackson2LinkIntegrationTest.java b/src/test/java/org/springframework/hateoas/Jackson2LinkIntegrationTest.java
new file mode 100644
index 00000000..4868d47f
--- /dev/null
+++ b/src/test/java/org/springframework/hateoas/Jackson2LinkIntegrationTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2012 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;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+/**
+ * Integration tests for {@link org.springframework.hateoas.Link} marshaling.
+ *
+ * @author Oliver Gierke
+ * @author Jon Brisbin
+ */
+public class Jackson2LinkIntegrationTest extends AbstractJackson2MarshallingIntegrationTests {
+
+ private static final String REFERENCE = "{\"rel\":\"something\",\"href\":\"location\"}";
+
+ /**
+ * @see #27
+ */
+ @Test
+ public void writesLinkCorrectly() throws Exception {
+ assertThat(write(new Link("location", "something")), is(REFERENCE));
+ }
+
+ /**
+ * @see #27
+ */
+ @Test
+ public void readsLinkCorrectly() throws Exception {
+ Link result = read(REFERENCE, Link.class);
+ assertThat(result.getHref(), is("location"));
+ assertThat(result.getRel(), is("something"));
+ }
+}
diff --git a/src/test/java/org/springframework/hateoas/Jackson2ResourceIntegrationTest.java b/src/test/java/org/springframework/hateoas/Jackson2ResourceIntegrationTest.java
new file mode 100644
index 00000000..a4d4b685
--- /dev/null
+++ b/src/test/java/org/springframework/hateoas/Jackson2ResourceIntegrationTest.java
@@ -0,0 +1,65 @@
+package org.springframework.hateoas;
+
+import static org.hamcrest.MatcherAssert.*;
+import static org.hamcrest.Matchers.*;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+
+/**
+ * Integration tests for {@link Resource}.
+ *
+ * @author Oliver Gierke
+ * @author Jon Brisbin
+ */
+public class Jackson2ResourceIntegrationTest extends AbstractJackson2MarshallingIntegrationTests {
+
+ static final String REFERENCE = "{\"links\":[{\"rel\":\"self\",\"href\":\"localhost\"}],\"firstname\":\"Dave\",\"lastname\":\"Matthews\"}";
+
+ /**
+ * @see #27
+ * @throws Exception
+ */
+ @Test
+ public void inlinesContent() throws Exception {
+
+ Person person = new Person();
+ person.firstname = "Dave";
+ person.lastname = "Matthews";
+
+ Resource resource = new Resource(person);
+ resource.add(new Link("localhost"));
+
+ assertThat(write(resource), is(REFERENCE));
+ }
+
+ /**
+ * @see #27
+ */
+ @Test
+ public void readsResourceSupportCorrectly() throws Exception {
+
+ PersonResource result = read(REFERENCE, PersonResource.class);
+
+ assertThat(result.getLinks(), hasSize(1));
+ assertThat(result.getLinks(), hasItem(new Link("localhost")));
+ assertThat(result.getContent().firstname, is("Dave"));
+ assertThat(result.getContent().lastname, is("Matthews"));
+ }
+
+ static class PersonResource extends Resource {
+
+ public PersonResource() {
+
+ }
+ }
+
+ @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
+ static class Person {
+
+ String firstname;
+ String lastname;
+ }
+
+}
diff --git a/src/test/java/org/springframework/hateoas/Jackson2ResourceSupportIntegrationTest.java b/src/test/java/org/springframework/hateoas/Jackson2ResourceSupportIntegrationTest.java
new file mode 100644
index 00000000..a72f9142
--- /dev/null
+++ b/src/test/java/org/springframework/hateoas/Jackson2ResourceSupportIntegrationTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2012 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;
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+/**
+ * Integration tests for {@link org.springframework.hateoas.ResourceSupport}.
+ *
+ * @author Oliver Gierke
+ */
+public class Jackson2ResourceSupportIntegrationTest extends AbstractJackson2MarshallingIntegrationTests {
+
+ static final String REFERENCE = "{\"links\":[{\"rel\":\"self\",\"href\":\"localhost\"}]}";
+
+ /**
+ * @see #27
+ */
+ @Test
+ public void doesNotRenderId() throws Exception {
+
+ ResourceSupport resourceSupport = new ResourceSupport();
+ resourceSupport.add(new Link("localhost"));
+
+ assertThat(write(resourceSupport), is(REFERENCE));
+ }
+
+ /**
+ * @see #27
+ */
+ @Test
+ public void readResourceSupportCorrectly() throws Exception {
+
+ ResourceSupport result = read(REFERENCE, ResourceSupport.class);
+
+ assertThat(result.getLinks(), hasSize(1));
+ assertThat(result.getLinks(), hasItem(new Link("localhost")));
+ }
+}
diff --git a/template.mf b/template.mf
index 727f7cdc..3b056f9a 100644
--- a/template.mf
+++ b/template.mf
@@ -3,7 +3,8 @@ Bundle-Name: Spring HATEOAS
Bundle-Vendor: SpringSource
Bundle-ManifestVersion: 2
Import-Template:
+ com.fasterxml.jackson.*;version="${jackson2.version:[=.=.=,+1.0.0)}";resolution:=optional,
+ javax.ws.rs.*;version="${jaxrs.version:[=.=.=,+1.0.0)}";resolution:=optional,
javax.xml.bind.*;version="0",
org.springframework.*;version="${spring.version:[=.=.=,+1.0.0)}";resolution:=optional,
- org.codehaus.jackson.*;version="${jackson.version:[=.=.=,+1.0.0)}";resolution:=optional,
- javax.ws.rs.*;version="${jaxrs.version:[=.=.=,+1.0.0)}";resolution:=optional
+ org.codehaus.jackson.*;version="${jackson1.version:[=.=.=,+1.0.0)}";resolution:=optional