#286 - EmbeddedWrappers now allows empty collections if a rel or type is provided.

EmbeddedWrappers.wrap(Object, String) now allows empty collections. Also a new emptyCollectionOfType(Class<?>) was introduced to allow the RelProvider kick in and dynamically resolve the lazily.

Added more details to the JavaDoc of EmbeddedWrapper to make clear that we either expect a static rel returned or a type to resolve the rel from. Make HalEmbeddedBuilder detect invalid implementations and reject them although that should never occur if users use EmbeddedWrappers factory.
This commit is contained in:
Oliver Gierke
2015-02-10 14:49:43 +01:00
parent c41b28e00d
commit a90e2f32c3
5 changed files with 188 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 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.
@@ -39,6 +39,7 @@ import org.springframework.util.StringUtils;
class HalEmbeddedBuilder {
private static final String DEFAULT_REL = "content";
private static final String INVALID_EMBEDDED_WRAPPER = "Embedded wrapper %s returned null for both the static rel and the rel target type! Make sure one of the two returns a non-null value!";
private final Map<String, Object> embeddeds = new HashMap<String, Object>();
private final RelProvider provider;
@@ -117,6 +118,10 @@ class HalEmbeddedBuilder {
Class<?> type = wrapper.getRelTargetType();
if (type == null) {
throw new IllegalStateException(String.format(INVALID_EMBEDDED_WRAPPER, wrapper));
}
String rel = forCollection ? provider.getCollectionResourceRelFor(type) : provider.getItemResourceRelFor(type);
if (curieProvider != null) {