DATAREST-491 - Fixed handling of non-entity maps in JSON processing.
During our custom JSON handling on PUT requests, we previously piped all JSON objects through code that expected that one to be mapped to a PersistentEntity. This fails for JSON objects that basically represent maps. We now skip that code paths for non-entity properties.
This commit is contained in:
@@ -181,7 +181,7 @@ public class DomainObjectReader {
|
||||
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(target);
|
||||
Object nested = accessor.getProperty(property);
|
||||
|
||||
if (nested != null) {
|
||||
if (nested != null && property.isEntity()) {
|
||||
doMerge((ObjectNode) child, nested, mapper);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -256,4 +257,21 @@ public class MongoWebTests extends CommonWebTests {
|
||||
andExpect(status().isOk()).//
|
||||
andExpect(jsonPath("$").exists());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREST-491
|
||||
*/
|
||||
@Test
|
||||
public void updatesMapPropertyCorrectly() throws Exception {
|
||||
|
||||
Link profilesLink = client.discoverUnique("profiles");
|
||||
Link profileLink = assertHasContentLinkWithRel("self", client.request(profilesLink));
|
||||
|
||||
Profile profile = new Profile();
|
||||
profile.setMetadata(Collections.singletonMap("Key", "Value"));
|
||||
|
||||
putAndGet(profileLink, mapper.writeValueAsString(profile), MediaType.APPLICATION_JSON);
|
||||
|
||||
client.follow(profileLink).andExpect(jsonPath("$.metadata.Key").value("Value"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,23 @@
|
||||
/*
|
||||
* Copyright 2012-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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.rest.webmvc.mongodb;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
@@ -20,6 +37,7 @@ public class Profile {
|
||||
private @JsonProperty(required = true) String type;
|
||||
private @LastModifiedDate Date lastModifiedDate;
|
||||
private @JsonProperty("renamed") String aliased;
|
||||
private Map<String, String> metadata = new HashMap<String, String>();
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
@@ -56,4 +74,12 @@ public class Profile {
|
||||
public String getAliased() {
|
||||
return aliased;
|
||||
}
|
||||
|
||||
public Map<String, String> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(Map<String, String> metadata) {
|
||||
this.metadata = metadata;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user