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:
Oliver Gierke
2015-03-20 09:36:50 +01:00
parent 3b0e34e98a
commit 8414b290b9
3 changed files with 48 additions and 2 deletions

View File

@@ -181,7 +181,7 @@ public class DomainObjectReader {
BeanWrapper<T> wrapper = BeanWrapper.create(target, null);
Object nested = wrapper.getProperty(property);
if (nested != null) {
if (nested != null && property.isEntity()) {
doMerge((ObjectNode) child, nested, mapper);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-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.
@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.util.Arrays;
import java.util.Collections;
import org.junit.After;
import org.junit.Before;
@@ -32,6 +33,7 @@ import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.JsonPath;
/**
@@ -148,4 +150,21 @@ public class MongoWebTests extends CommonWebTests {
assertThat(JsonPath.read(response.getContentAsString(), "$.lastname"), is(nullValue()));
assertThat(JsonPath.read(response.getContentAsString(), "$.address.zipCode"), is((Object) "ZIP"));
}
/**
* @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, new ObjectMapper().writeValueAsString(profile), MediaType.APPLICATION_JSON);
client.follow(profileLink).andExpect(jsonPath("$.metadata.Key").value("Value"));
}
}

View File

@@ -1,10 +1,29 @@
/*
* 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.HashMap;
import java.util.Map;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @author Jon Brisbin
* @author Oliver Gierke
*/
@Document
public class Profile {
@@ -12,6 +31,7 @@ public class Profile {
@Id private String id;
private Long person;
private String type;
private Map<String, String> metadata = new HashMap<String, String>();
public String getId() {
return id;
@@ -40,4 +60,11 @@ public class Profile {
return this;
}
public Map<String, String> getMetadata() {
return metadata;
}
public void setMetadata(Map<String, String> metadata) {
this.metadata = metadata;
}
}