List of usage examples for org.springframework.data.rest.webmvc.json JacksonMetadata isExported
public boolean isExported(PersistentProperty<?> property)
From source file:org.springframework.data.rest.webmvc.json.JacksonMetadataUnitTests.java
/** * @see DATAREST-644/*from ww w . jav a 2s .co m*/ */ @Test public void detectsReadOnlyProperty() { JacksonMetadata metadata = new JacksonMetadata(mapper, User.class); PersistentEntity<?, ?> entity = context.getPersistentEntity(User.class); PersistentProperty<?> property = entity.getPersistentProperty("username"); assertThat(metadata.isExported(property), is(true)); assertThat(metadata.isReadOnly(property), is(true)); }
From source file:org.springframework.data.rest.webmvc.alps.RootResourceInformationToAlpsDescriptorConverter.java
private List<Descriptor> buildPropertyDescriptors(final Class<?> type, String baseRel) { final PersistentEntity<?, ?> entity = persistentEntities.getPersistentEntity(type); final List<Descriptor> propertyDescriptors = new ArrayList<Descriptor>(); final JacksonMetadata jackson = new JacksonMetadata(mapper, type); final ResourceMetadata metadata = associations.getMetadataFor(entity.getType()); entity.doWithProperties(new SimplePropertyHandler() { @Override/*ww w. ja va 2 s . c o m*/ public void doWithPersistentProperty(PersistentProperty<?> property) { BeanPropertyDefinition propertyDefinition = jackson.getDefinitionFor(property); ResourceMapping propertyMapping = metadata.getMappingFor(property); if (propertyDefinition != null) { if (property.isIdProperty() && !configuration.isIdExposedFor(property.getOwner().getType())) { return; } propertyDescriptors.add(// descriptor(). // type(Type.SEMANTIC).// name(propertyDefinition.getName()).// doc(getDocFor(propertyMapping.getDescription(), property)).// build()); } } }); entity.doWithAssociations(new SimpleAssociationHandler() { @Override public void doWithAssociation(Association<? extends PersistentProperty<?>> association) { PersistentProperty<?> property = association.getInverse(); if (!jackson.isExported(property) || !associations.isLinkableAssociation(property)) { return; } ResourceMapping mapping = metadata.getMappingFor(property); DescriptorBuilder builder = descriptor().// name(mapping.getRel()).doc(getDocFor(mapping.getDescription())); ResourceMetadata targetTypeMetadata = associations.getMetadataFor(property.getActualType()); String href = ProfileController.getPath(configuration, targetTypeMetadata) + "#" + getRepresentationDescriptorId(targetTypeMetadata); Link link = new Link(href).withSelfRel(); builder.// type(Type.SAFE).// rt(link.getHref()); propertyDescriptors.add(builder.build()); } }); return propertyDescriptors; }