List of usage examples for org.springframework.data.rest.webmvc.json MappedProperties getMappedName
public String getMappedName(PersistentProperty<?> property)
From source file:org.springframework.data.rest.webmvc.json.DomainObjectReader.java
/** * Reads the given source node onto the given target object and applies PUT semantics, i.e. explicitly * //from w w w . j a v a 2s . c o m * @param source must not be {@literal null}. * @param target must not be {@literal null}. * @param mapper * @return */ public <T> T readPut(final ObjectNode source, T target, final ObjectMapper mapper) { Assert.notNull(source, "ObjectNode must not be null!"); Assert.notNull(target, "Existing object instance must not be null!"); Assert.notNull(mapper, "ObjectMapper must not be null!"); Class<? extends Object> type = target.getClass(); final PersistentEntity<?, ?> entity = entities.getPersistentEntity(type); Assert.notNull(entity, "No PersistentEntity found for ".concat(type.getName()).concat("!")); final MappedProperties properties = getJacksonProperties(entity, mapper); entity.doWithProperties(new SimplePropertyHandler() { /* * (non-Javadoc) * @see org.springframework.data.mapping.SimplePropertyHandler#doWithPersistentProperty(org.springframework.data.mapping.PersistentProperty) */ @Override public void doWithPersistentProperty(PersistentProperty<?> property) { if (property.isIdProperty() || property.isVersionProperty()) { return; } String mappedName = properties.getMappedName(property); boolean isMappedProperty = mappedName != null; boolean noValueInSource = !source.has(mappedName); if (isMappedProperty && noValueInSource) { source.putNull(mappedName); } } }); return merge(source, target, mapper); }