SPR-7210 Add setModelKey and setModelKeys to MappingJacksonJsonView for consistency with MarshallingView.

This commit is contained in:
Rossen Stoyanchev
2011-06-22 19:08:44 +00:00
parent 6fa451733e
commit 5797fe7f62
2 changed files with 49 additions and 16 deletions

View File

@@ -16,6 +16,13 @@
package org.springframework.web.servlet.view.json;
import static org.easymock.EasyMock.createMock;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
@@ -31,14 +38,11 @@ import org.codehaus.jackson.map.SerializerFactory;
import org.codehaus.jackson.map.SerializerProvider;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.ser.BeanSerializerFactory;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.ScriptableObject;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.validation.BindingResult;
@@ -153,7 +157,8 @@ public class MappingJacksonJsonViewTest {
public void renderWithCustomSerializerLocatedByFactory() throws Exception {
SerializerFactory factory = new DelegatingSerializerFactory();
ObjectMapper mapper = new ObjectMapper(factory);
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializerFactory(factory);
view.setObjectMapper(mapper);
Object bean = new TestBeanSimple();
@@ -178,7 +183,7 @@ public class MappingJacksonJsonViewTest {
attrs.add("baz");
attrs.add("nil");
view.setRenderedAttributes(attrs);
view.setModelKeys(attrs);
Map<String, Object> model = new HashMap<String, Object>();
model.put("foo", "foo");
model.put("bar", "bar");
@@ -207,6 +212,7 @@ public class MappingJacksonJsonViewTest {
assertSame(bean, actual);
}
@SuppressWarnings("rawtypes")
@Test
public void filterTwoKeyModel() throws Exception {
view.setExtractValueFromSingleKeyModel(true);