From 629028a7efa7a98c99e3559938279cea468270bb Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 10 Feb 2015 15:28:13 +0100 Subject: [PATCH] #236, #286 - Added test case to show how to add empty embedded collections. --- .../hateoas/hal/Jackson2HalIntegrationTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java b/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java index af459a2e..1ff09e28 100644 --- a/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java @@ -36,6 +36,7 @@ import org.springframework.hateoas.ResourceSupport; import org.springframework.hateoas.Resources; import org.springframework.hateoas.UriTemplate; import org.springframework.hateoas.core.AnnotationRelProvider; +import org.springframework.hateoas.core.EmbeddedWrappers; import org.springframework.hateoas.hal.Jackson2HalModule.HalHandlerInstantiator; import com.fasterxml.jackson.databind.ObjectMapper; @@ -344,6 +345,22 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg assertThat(getCuriedObjectMapper(provider).writeValueAsString(resources), is(MULTIPLE_CURIES_DOCUMENT)); } + /** + * @see #286, #236 + */ + @Test + public void rendersEmptyEmbeddedCollections() throws Exception { + + EmbeddedWrappers wrappers = new EmbeddedWrappers(false); + + List values = new ArrayList(); + values.add(wrappers.emptyCollectionOf(SimpleAnnotatedPojo.class)); + + Resources resources = new Resources(values); + + assertThat(write(resources), is("{\"_embedded\":{\"pojos\":[]}}")); + } + private static Resources> setupAnnotatedPagedResources() { List> content = new ArrayList>();