DATAREST-250 - Fixed exposure of inline properties.

Fixed PersistentEntityResource serialization to correctly export associations that are not backed by an exported repository.
This commit is contained in:
Oliver Gierke
2014-02-21 11:53:18 +01:00
parent 3e5914d84f
commit 44fda4f8b7
3 changed files with 13 additions and 21 deletions

View File

@@ -190,10 +190,7 @@ public class PersistentEntityJackson2Module extends SimpleModule {
public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {
PersistentProperty<?> property = association.getInverse();
if (maybeAddAssociationLink(builder, mappings, property, links)) {
return;
}
maybeAddAssociationLink(builder, mappings, property, links);
}
});
@@ -250,23 +247,12 @@ public class PersistentEntityJackson2Module extends SimpleModule {
PersistentProperty<?> persistentProperty = entity.getPersistentProperty(writer.getName());
if (persistentProperty.isAssociation()) {
if (!resourceMetadata.isManagedResource(persistentProperty)) {
continue;
}
if (mappings.getMappingFor(persistentProperty.getActualType()).isExported()) {
continue;
}
ResourceMapping propertyMapping = resourceMetadata.getMappingFor(persistentProperty);
if (!propertyMapping.isExported()) {
continue;
}
// Skip exported associations
if (persistentProperty.isAssociation() && resourceMetadata.isExported(persistentProperty)) {
continue;
}
// Skip ids unless explicitly configured to expose
if (persistentProperty.isIdProperty() && !configuration.isIdExposedFor(entity.getType())) {
continue;
}

View File

@@ -259,6 +259,11 @@ public abstract class AbstractWebIntegrationTests {
Object jsonPathResult = JsonPath.read(response.getContentAsString(), path);
assertThat(jsonPathResult, is(notNullValue()));
if (jsonPathResult instanceof JSONArray) {
JSONArray array = (JSONArray) jsonPathResult;
assertThat(array, hasSize(greaterThan(0)));
}
return (T) jsonPathResult;
}
@@ -267,8 +272,7 @@ public abstract class AbstractWebIntegrationTests {
try {
JsonPath.read(response.getContentAsString(), path);
fail(path + " should have failed");
} catch (InvalidPathException e) {
}
} catch (InvalidPathException e) {}
}
protected String assertJsonPathEquals(String path, String expected, MockHttpServletResponse response)

View File

@@ -21,6 +21,8 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.data.rest.webmvc.jpa.JpaWebTests;
/**
* Test helper methods.
*
* @author Oliver Gierke
*/
public class TestUtils {