diff --git a/src/main/java/org/springframework/hateoas/core/ObjectUtils.java b/src/main/java/org/springframework/hateoas/core/ObjectUtils.java index 0f53664e..2963e750 100644 --- a/src/main/java/org/springframework/hateoas/core/ObjectUtils.java +++ b/src/main/java/org/springframework/hateoas/core/ObjectUtils.java @@ -15,7 +15,6 @@ */ package org.springframework.hateoas.core; -import org.springframework.aop.framework.Advised; import org.springframework.hateoas.Resource; /** @@ -32,25 +31,12 @@ public class ObjectUtils { * @param object can be {@literal null}. * @return */ - public static Class getResourceType(Object object) { + public static Object getResourceType(Object object) { if (object instanceof Resource) { - return nullSafeType(((Resource) object).getContent()); + return ((Resource) object).getContent(); } - return nullSafeType(object); - } - - private static Class nullSafeType(Object object) { - - if (object == null) { - return null; - } - - if (object instanceof Advised) { - return ((Advised) object).getTargetClass(); - } - - return object.getClass(); + return object; } } diff --git a/src/main/java/org/springframework/hateoas/hal/HalEmbeddedBuilder.java b/src/main/java/org/springframework/hateoas/hal/HalEmbeddedBuilder.java index ff52d4c7..bf9b4b89 100644 --- a/src/main/java/org/springframework/hateoas/hal/HalEmbeddedBuilder.java +++ b/src/main/java/org/springframework/hateoas/hal/HalEmbeddedBuilder.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.springframework.aop.support.AopUtils; import org.springframework.hateoas.RelProvider; import org.springframework.hateoas.Resource; import org.springframework.hateoas.core.ObjectUtils; @@ -58,16 +59,16 @@ class HalEmbeddedBuilder { */ public void add(Object value) { - Class type = ObjectUtils.getResourceType(value); + Object unwrapped = ObjectUtils.getResourceType(value); - if (type == null) { + if (unwrapped == null) { return; } - String rel = getDefaultedRelFor(type, true); + String rel = getDefaultedRelFor(unwrapped, true); if (!embeddeds.containsKey(rel)) { - rel = getDefaultedRelFor(type, enforceCollections); + rel = getDefaultedRelFor(unwrapped, enforceCollections); } List currentValue = embeddeds.get(rel); @@ -79,18 +80,20 @@ class HalEmbeddedBuilder { } else if (currentValue.size() == 1) { currentValue.add(value); embeddeds.remove(rel); - embeddeds.put(getDefaultedRelFor(type, true), currentValue); + embeddeds.put(getDefaultedRelFor(unwrapped, true), currentValue); } else { currentValue.add(value); } } - private String getDefaultedRelFor(Class type, boolean forCollection) { + private String getDefaultedRelFor(Object value, boolean forCollection) { if (provider == null) { return DEFAULT_REL; } + Class type = AopUtils.getTargetClass(value); + String rel = forCollection ? provider.getCollectionResourceRelFor(type) : provider.getItemResourceRelFor(type); return rel == null ? DEFAULT_REL : rel; }