diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/AttributeMetadata.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/AttributeMetadata.java
index 086ae9dff..2d2823c4e 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/AttributeMetadata.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/AttributeMetadata.java
@@ -1,5 +1,6 @@
package org.springframework.data.rest.repository;
+import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
@@ -90,6 +91,27 @@ public interface AttributeMetadata {
*/
Map asMap(Object target);
+ /**
+ * Does this attribute have the given annotation on it?
+ *
+ * @param annoType
+ * The type of annotation to search for.
+ *
+ * @return {@literal true} if this annotation exists on this attribute, {@literal false} otherwise.
+ */
+ boolean hasAnnotation(Class extends Annotation> annoType);
+
+ /**
+ * Get the given annotation.
+ *
+ * @param annoType
+ * The type of annotation to get.
+ * @param
+ *
+ * @return The annotation, or {@literal null} if it doesn't exist.
+ */
+ A annotation(Class annoType);
+
/**
* Get the path of this attribute.
*
diff --git a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/jpa/JpaAttributeMetadata.java b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/jpa/JpaAttributeMetadata.java
index 109bf3861..8b6ebb064 100644
--- a/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/jpa/JpaAttributeMetadata.java
+++ b/spring-data-rest-repository/src/main/java/org/springframework/data/rest/repository/jpa/JpaAttributeMetadata.java
@@ -1,6 +1,7 @@
package org.springframework.data.rest.repository.jpa;
import java.beans.PropertyDescriptor;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
@@ -126,6 +127,14 @@ public class JpaAttributeMetadata implements AttributeMetadata {
return (Map)get(target);
}
+ @Override public boolean hasAnnotation(Class extends Annotation> annoType) {
+ return field.isAnnotationPresent(annoType);
+ }
+
+ @Override public A annotation(Class annoType) {
+ return field.getAnnotation(annoType);
+ }
+
@Override public Object get(Object target) {
try {
if(null != getter) {
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryAwareMappingHttpMessageConverter.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryAwareMappingHttpMessageConverter.java
index a66b7c1e2..f155a34c9 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryAwareMappingHttpMessageConverter.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryAwareMappingHttpMessageConverter.java
@@ -74,13 +74,11 @@ public class RepositoryAwareMappingHttpMessageConverter
MediaTypes.COMPACT_JSON,
MediaTypes.VERBOSE_JSON
));
-
- mapper.registerModule(new RepositoryAwareModule());
-
setObjectMapper(mapper);
}
@Override public void afterPropertiesSet() throws Exception {
+ mapper.registerModule(new RepositoryAwareModule());
for(Module m : modules) {
mapper.registerModule(m);
}
@@ -194,6 +192,12 @@ public class RepositoryAwareMappingHttpMessageConverter
}
private class RepositoryAwareModule extends SimpleModule {
+
+ SimpleSerializers sers = new SimpleSerializers();
+ SimpleDeserializers dsers = new SimpleDeserializers();
+ SimpleSerializers keySers = new SimpleSerializers();
+ SimpleKeyDeserializers keyDsers = new SimpleKeyDeserializers();
+
private RepositoryAwareModule() {
super("RepositoryAwareModule", new Version(1, 0, 0, "SNAPSHOT"));
}
@@ -204,10 +208,6 @@ public class RepositoryAwareMappingHttpMessageConverter
new SimpleAbstractTypeResolver()
.addMapping(Link.class, ResourceLink.class)
);
- SimpleSerializers sers = new SimpleSerializers();
- SimpleDeserializers dsers = new SimpleDeserializers();
- SimpleSerializers keySers = new SimpleSerializers();
- SimpleKeyDeserializers keyDsers = new SimpleKeyDeserializers();
for(RepositoryExporter repoExp : repositoryExporters) {
for(String repoName : new ArrayList(repoExp.repositoryNames())) {
diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestController.java
index ac47bcd49..6514fdc64 100644
--- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestController.java
+++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryRestController.java
@@ -20,6 +20,8 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicReference;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToOne;
import javax.servlet.http.HttpServletRequest;
import org.codehaus.jackson.map.ObjectMapper;
@@ -1065,9 +1067,9 @@ public class RepositoryRestController
AttributeMetadata idAttr = propRepoMeta.entityMetadata().idAttribute();
String propertyRel = repository +
"." + entity.getClass().getSimpleName() +
- "." + property +
- "." + propRepoMeta.entityMetadata().type().getSimpleName();
+ "." + property;
if(propVal instanceof Collection) {
+ propertyRel += "." + propRepoMeta.entityMetadata().type().getSimpleName();
ResourceSet resources = new ResourceSet();
for(Object o : (Collection)propVal) {
String propValId = idAttr.get(o).toString();
@@ -1088,6 +1090,7 @@ public class RepositoryRestController
}
body = resources;
} else if(propVal instanceof Map) {
+ propertyRel += "." + propRepoMeta.entityMetadata().type().getSimpleName();
Map resource = new HashMap();
for(Map.Entry