From 4ece75b6257690f865e5ad9620c3a4b8e14a09e7 Mon Sep 17 00:00:00 2001 From: Jon Brisbin Date: Thu, 6 Sep 2012 09:27:20 -0500 Subject: [PATCH] Tests added looking into #35 --- .../json/RepositoryAwareJacksonModule.java | 5 +-- .../data/rest/test/webmvc/Child.java | 29 +++++++++++++++ .../rest/test/webmvc/ChildRepository.java | 9 +++++ .../data/rest/test/webmvc/Parent.java | 37 +++++++++++++++++++ .../rest/test/webmvc/ParentRepository.java | 9 +++++ 5 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/Child.java create mode 100644 spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/ChildRepository.java create mode 100644 spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/Parent.java create mode 100644 spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/ParentRepository.java diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/RepositoryAwareJacksonModule.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/RepositoryAwareJacksonModule.java index 567665a1f..a184961fb 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/RepositoryAwareJacksonModule.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/RepositoryAwareJacksonModule.java @@ -97,10 +97,7 @@ public class RepositoryAwareJacksonModule extends SimpleModule implements Initia } } - if(!conversionService.canConvert(domainType, Resource.class)) { - // Assign only if no custom converter already assigned - conversionService.addConverter(domainType, Resource.class, new EntityToResourceConverter(repoMeta)); - } + conversionService.addConverter(domainType, Resource.class, new EntityToResourceConverter(repoMeta)); sers.addSerializer(domainType, new DomainObjectToResourceSerializer(domainType)); keySers.addSerializer(domainType, new DomainObjectToStringKeySerializer(domainType, repoMeta)); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/Child.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/Child.java new file mode 100644 index 000000000..719b9c8ed --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/Child.java @@ -0,0 +1,29 @@ +package org.springframework.data.rest.test.webmvc; + +import javax.persistence.Entity; + +/** + * @author Jon Brisbin + */ +@Entity +public class Child extends Parent { + + private String occupation; + + public Child() { + } + + public Child(String name, String occupation) { + super(name); + this.occupation = occupation; + } + + public String getOccupation() { + return occupation; + } + + public void setOccupation(String occupation) { + this.occupation = occupation; + } + +} diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/ChildRepository.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/ChildRepository.java new file mode 100644 index 000000000..1b7ffaeba --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/ChildRepository.java @@ -0,0 +1,9 @@ +package org.springframework.data.rest.test.webmvc; + +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @author Jon Brisbin + */ +public interface ChildRepository extends JpaRepository { +} diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/Parent.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/Parent.java new file mode 100644 index 000000000..68b2de681 --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/Parent.java @@ -0,0 +1,37 @@ +package org.springframework.data.rest.test.webmvc; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; + +/** + * @author Jon Brisbin + */ +@Entity +@Inheritance(strategy = InheritanceType.JOINED) +public class Parent { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + + public Parent() { + } + + public Parent(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/ParentRepository.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/ParentRepository.java new file mode 100644 index 000000000..8e30d3272 --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/test/webmvc/ParentRepository.java @@ -0,0 +1,9 @@ +package org.springframework.data.rest.test.webmvc; + +import org.springframework.data.jpa.repository.JpaRepository; + +/** + * @author Jon Brisbin + */ +public interface ParentRepository extends JpaRepository { +}