Browse Source

Upgraded to Commons FileUpload 1.3.1, TestNG 6.8.7, Hibernate 4.2.8, Joda-Time 2.2, Jackson 1.7.9

pull/465/head
Juergen Hoeller 12 years ago
parent
commit
61ab40cd7a
  1. 40
      build.gradle
  2. 37
      spring-context/src/test/java/org/springframework/format/datetime/joda/JodaTimeFormattingTests.java
  3. 2
      spring-jms/src/main/java/org/springframework/jms/support/converter/MappingJacksonMessageConverter.java
  4. 34
      spring-jms/src/test/java/org/springframework/jms/support/converter/MappingJacksonMessageConverterTests.java
  5. 36
      spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonHttpMessageConverter.java
  6. 23
      spring-web/src/test/java/org/springframework/web/multipart/commons/CommonsMultipartResolverTests.java
  7. 2
      spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJacksonJsonView.java
  8. 71
      spring-webmvc/src/test/java/org/springframework/web/servlet/view/json/MappingJacksonJsonViewTests.java

40
build.gradle

@ -17,7 +17,7 @@ configure(allprojects) { project ->
// "Class not found: javac1.8" issue with Ant versions prior to 1.9.x // "Class not found: javac1.8" issue with Ant versions prior to 1.9.x
ant.properties["build.compiler"] = "javac1.7" ant.properties["build.compiler"] = "javac1.7"
ext.aspectjVersion = "1.7.2" ext.aspectjVersion = "1.7.4"
ext.hsqldbVersion = "1.8.0.10" ext.hsqldbVersion = "1.8.0.10"
ext.junitVersion = "4.11" ext.junitVersion = "4.11"
ext.slf4jVersion = "1.6.6" ext.slf4jVersion = "1.6.6"
@ -328,11 +328,11 @@ project("spring-context") {
optional("javax.persistence:persistence-api:1.0") optional("javax.persistence:persistence-api:1.0")
optional("javax.validation:validation-api:1.0.0.GA") optional("javax.validation:validation-api:1.0.0.GA")
optional("org.hibernate:hibernate-validator:4.3.1.Final") optional("org.hibernate:hibernate-validator:4.3.1.Final")
optional("joda-time:joda-time:2.1") optional("joda-time:joda-time:2.2")
optional("org.aspectj:aspectjweaver:${aspectjVersion}") optional("org.aspectj:aspectjweaver:${aspectjVersion}")
optional("org.codehaus.groovy:groovy-all:1.8.9") optional("org.codehaus.groovy:groovy-all:1.8.9")
optional("org.beanshell:bsh:2.0b4") optional("org.beanshell:bsh:2.0b4")
optional("org.jruby:jruby:1.7.2") optional("org.jruby:jruby:1.7.10")
testCompile("javax.inject:javax.inject-tck:1") testCompile("javax.inject:javax.inject-tck:1")
testCompile("commons-dbcp:commons-dbcp:1.3") testCompile("commons-dbcp:commons-dbcp:1.3")
testCompile("org.slf4j:slf4j-api:${slf4jVersion}") testCompile("org.slf4j:slf4j-api:${slf4jVersion}")
@ -406,7 +406,7 @@ project("spring-jms") {
optional("aopalliance:aopalliance:1.0") optional("aopalliance:aopalliance:1.0")
optional("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1") optional("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1")
optional("javax.resource:connector-api:1.5") optional("javax.resource:connector-api:1.5")
optional("org.codehaus.jackson:jackson-mapper-asl:1.4.5") optional("org.codehaus.jackson:jackson-mapper-asl:1.7.9")
optional("com.fasterxml.jackson.core:jackson-databind:2.0.6") optional("com.fasterxml.jackson.core:jackson-databind:2.0.6")
} }
} }
@ -444,7 +444,7 @@ project("spring-context-support") {
optional("org.quartz-scheduler:quartz:1.7.3") optional("org.quartz-scheduler:quartz:1.7.3")
optional("org.codehaus.fabric3.api:commonj:1.1.0") optional("org.codehaus.fabric3.api:commonj:1.1.0")
optional("velocity:velocity:1.5") optional("velocity:velocity:1.5")
optional("org.freemarker:freemarker:2.3.19") optional("org.freemarker:freemarker:2.3.20")
optional("com.lowagie:itext:2.1.7") optional("com.lowagie:itext:2.1.7")
optional("jasperreports:jasperreports:2.0.5") optional("jasperreports:jasperreports:2.0.5")
testCompile("org.apache.poi:poi:3.0.2-FINAL") testCompile("org.apache.poi:poi:3.0.2-FINAL")
@ -477,11 +477,11 @@ project("spring-web") {
optional("javax.xml.soap:saaj-api:1.3") optional("javax.xml.soap:saaj-api:1.3")
optional("aopalliance:aopalliance:1.0") optional("aopalliance:aopalliance:1.0")
optional("com.caucho:hessian:3.2.1") optional("com.caucho:hessian:3.2.1")
optional("commons-fileupload:commons-fileupload:1.2.2") optional("commons-fileupload:commons-fileupload:1.3.1")
optional("commons-io:commons-io:1.3") optional("commons-io:commons-io:1.3")
optional("commons-httpclient:commons-httpclient:3.1") optional("commons-httpclient:commons-httpclient:3.1")
optional("org.apache.httpcomponents:httpclient:4.2") optional("org.apache.httpcomponents:httpclient:4.2.6")
optional("org.codehaus.jackson:jackson-mapper-asl:1.4.5") optional("org.codehaus.jackson:jackson-mapper-asl:1.7.9")
optional("com.fasterxml.jackson.core:jackson-databind:2.0.6") optional("com.fasterxml.jackson.core:jackson-databind:2.0.6")
optional("rome:rome:1.0") optional("rome:rome:1.0")
optional("taglibs:standard:1.1.2") optional("taglibs:standard:1.1.2")
@ -547,8 +547,8 @@ project("spring-orm-hibernate4") {
provided(project(":spring-jdbc")) provided(project(":spring-jdbc"))
provided(project(":spring-tx")) provided(project(":spring-tx"))
optional(project(":spring-web")) optional(project(":spring-web"))
optional("org.hibernate:hibernate-core:4.1.9.Final") optional("org.hibernate:hibernate-core:4.2.8.Final")
optional("org.hibernate:hibernate-entitymanager:4.1.9.Final") optional("org.hibernate:hibernate-entitymanager:4.2.8.Final")
optional("javax.servlet:servlet-api:2.5") optional("javax.servlet:servlet-api:2.5")
} }
} }
@ -567,16 +567,16 @@ project("spring-webmvc") {
optional(project(":spring-oxm")) // for MarshallingView optional(project(":spring-oxm")) // for MarshallingView
optional("javax.servlet.jsp:jsp-api:2.1") optional("javax.servlet.jsp:jsp-api:2.1")
optional("javax.servlet:jstl:1.2") optional("javax.servlet:jstl:1.2")
optional("net.sourceforge.jexcelapi:jxl:2.6.3") optional("net.sourceforge.jexcelapi:jxl:2.6.12")
optional("org.apache.poi:poi:3.0.2-FINAL") optional("org.apache.poi:poi:3.0.2-FINAL")
optional("velocity:velocity:1.5") optional("velocity:velocity:1.5")
optional("velocity-tools:velocity-tools-view:1.4") optional("velocity-tools:velocity-tools-view:1.4")
optional("org.freemarker:freemarker:2.3.19") optional("org.freemarker:freemarker:2.3.20")
optional("com.lowagie:itext:2.1.7") optional("com.lowagie:itext:2.1.7")
optional("jasperreports:jasperreports:2.0.5") { optional("jasperreports:jasperreports:2.0.5") {
exclude group: "xml-apis", module: "xml-apis" exclude group: "xml-apis", module: "xml-apis"
} }
optional("org.codehaus.jackson:jackson-mapper-asl:1.4.5") optional("org.codehaus.jackson:jackson-mapper-asl:1.7.9")
optional("com.fasterxml.jackson.core:jackson-databind:2.0.6") optional("com.fasterxml.jackson.core:jackson-databind:2.0.6")
optional("rome:rome:1.0") optional("rome:rome:1.0")
optional("org.apache.tiles:tiles-api:2.1.2") optional("org.apache.tiles:tiles-api:2.1.2")
@ -602,8 +602,8 @@ project("spring-webmvc") {
} }
testCompile("javax.validation:validation-api:1.0.0.GA") testCompile("javax.validation:validation-api:1.0.0.GA")
testCompile("org.hibernate:hibernate-validator:4.3.1.Final") testCompile("org.hibernate:hibernate-validator:4.3.1.Final")
testCompile("org.apache.httpcomponents:httpclient:4.2") testCompile("org.apache.httpcomponents:httpclient:4.2.6")
testCompile("commons-fileupload:commons-fileupload:1.2.2") testCompile("commons-fileupload:commons-fileupload:1.3.1")
testCompile("commons-io:commons-io:1.3") testCompile("commons-io:commons-io:1.3")
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}") testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
} }
@ -656,7 +656,7 @@ project("spring-webmvc-portlet") {
compile(project(":spring-webmvc")) compile(project(":spring-webmvc"))
provided("javax.servlet:servlet-api:2.5") provided("javax.servlet:servlet-api:2.5")
provided("javax.portlet:portlet-api:2.0") provided("javax.portlet:portlet-api:2.0")
optional("commons-fileupload:commons-fileupload:1.2.2") optional("commons-fileupload:commons-fileupload:1.3.1")
} }
// pick up DispatcherPortlet.properties in src/main // pick up DispatcherPortlet.properties in src/main
@ -678,7 +678,7 @@ project("spring-test") {
optional(project(":spring-webmvc")) optional(project(":spring-webmvc"))
optional(project(":spring-webmvc-portlet")) optional(project(":spring-webmvc-portlet"))
optional("junit:junit:${junitVersion}") optional("junit:junit:${junitVersion}")
optional("org.testng:testng:6.5.2") optional("org.testng:testng:6.8.7")
optional("javax.inject:javax.inject:1") optional("javax.inject:javax.inject:1")
optional("javax.servlet:servlet-api:2.5") optional("javax.servlet:servlet-api:2.5")
optional("javax.servlet.jsp:jsp-api:2.1") optional("javax.servlet.jsp:jsp-api:2.1")
@ -732,7 +732,7 @@ project("spring-test-mvc") {
testCompile("javax.mail:mail:1.4.7") testCompile("javax.mail:mail:1.4.7")
testCompile("org.hibernate:hibernate-validator:4.3.1.Final") testCompile("org.hibernate:hibernate-validator:4.3.1.Final")
testCompile("com.thoughtworks.xstream:xstream:1.3.1") testCompile("com.thoughtworks.xstream:xstream:1.3.1")
testCompile("org.codehaus.jackson:jackson-mapper-asl:1.4.5") testCompile("org.codehaus.jackson:jackson-mapper-asl:1.7.9")
testCompile("com.fasterxml.jackson.core:jackson-databind:2.0.6") testCompile("com.fasterxml.jackson.core:jackson-databind:2.0.6")
testCompile("rome:rome:1.0") testCompile("rome:rome:1.0")
testCompile("org.apache.tiles:tiles-request-api:1.0.1") testCompile("org.apache.tiles:tiles-request-api:1.0.1")
@ -865,7 +865,7 @@ configure(rootProject) {
testCompile("javax.inject:javax.inject:1") testCompile("javax.inject:javax.inject:1")
testCompile("javax.resource:connector-api:1.5") testCompile("javax.resource:connector-api:1.5")
testCompile("org.aspectj:aspectjweaver:${aspectjVersion}") testCompile("org.aspectj:aspectjweaver:${aspectjVersion}")
testCompile("org.hibernate:hibernate-core:4.1.9.Final") testCompile("org.hibernate:hibernate-core:4.2.8.Final")
testCompile("hsqldb:hsqldb:${hsqldbVersion}") testCompile("hsqldb:hsqldb:${hsqldbVersion}")
} }
@ -899,7 +899,7 @@ configure(rootProject) {
doFirst { doFirst {
classpath = files( classpath = files(
// ensure Servlet 3.x and Hibernate 4.x have precedence on the Javadoc // ensure Servlet 3.x and Hibernate 4.x have precedence on the javadoc
// classpath over their respective 2.5 and 3.x variants // classpath over their respective 2.5 and 3.x variants
project(":spring-webmvc").sourceSets.main.compileClasspath.files.find { it =~ "servlet-api" }, project(":spring-webmvc").sourceSets.main.compileClasspath.files.find { it =~ "servlet-api" },
rootProject.sourceSets.test.compileClasspath.files.find { it =~ "hibernate-core" }, rootProject.sourceSets.test.compileClasspath.files.find { it =~ "hibernate-core" },

37
spring-context/src/test/java/org/springframework/format/datetime/joda/JodaTimeFormattingTests.java

@ -16,11 +16,6 @@
package org.springframework.format.datetime.joda; package org.springframework.format.datetime.joda;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
@ -37,6 +32,7 @@ import org.joda.time.MutableDateTime;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.MutablePropertyValues;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.TypeDescriptor;
@ -46,6 +42,9 @@ import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.format.support.FormattingConversionService; import org.springframework.format.support.FormattingConversionService;
import org.springframework.validation.DataBinder; import org.springframework.validation.DataBinder;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/** /**
* @author Keith Donald * @author Keith Donald
* @author Juergen Hoeller * @author Juergen Hoeller
@ -236,21 +235,10 @@ public class JodaTimeFormattingTests {
@Test @Test
public void testBindLocalDateTimeAnnotated() { public void testBindLocalDateTimeAnnotated() {
MutablePropertyValues propertyValues = new MutablePropertyValues(); MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("localDateTimeAnnotated", "Saturday, October 31, 2009 12:00:00 PM "); propertyValues.add("localDateTimeAnnotated", "Oct 31, 2009 12:00 PM");
binder.bind(propertyValues); binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount()); assertEquals(0, binder.getBindingResult().getErrorCount());
assertEquals("Saturday, October 31, 2009 12:00:00 PM ", binder.getBindingResult().getFieldValue( assertEquals("Oct 31, 2009 12:00 PM", binder.getBindingResult().getFieldValue("localDateTimeAnnotated"));
"localDateTimeAnnotated"));
}
@Test
public void testBindLocalDateTimeAnnotatedLong() {
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("localDateTimeAnnotatedLong", "October 31, 2009 12:00:00 PM ");
binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount());
assertEquals("October 31, 2009 12:00:00 PM ", binder.getBindingResult().getFieldValue(
"localDateTimeAnnotatedLong"));
} }
@Test @Test
@ -510,12 +498,9 @@ public class JodaTimeFormattingTests {
private LocalDateTime localDateTime; private LocalDateTime localDateTime;
@DateTimeFormat(style="FF") @DateTimeFormat(style="MS")
private LocalDateTime localDateTimeAnnotated; private LocalDateTime localDateTimeAnnotated;
@DateTimeFormat(style="LL")
private LocalDateTime localDateTimeAnnotatedLong;
private DateTime dateTime; private DateTime dateTime;
@DateTimeFormat(style="MS") @DateTimeFormat(style="MS")
@ -612,14 +597,6 @@ public class JodaTimeFormattingTests {
this.localDateTimeAnnotated = localDateTimeAnnotated; this.localDateTimeAnnotated = localDateTimeAnnotated;
} }
public LocalDateTime getLocalDateTimeAnnotatedLong() {
return localDateTimeAnnotatedLong;
}
public void setLocalDateTimeAnnotatedLong(LocalDateTime localDateTimeAnnotatedLong) {
this.localDateTimeAnnotatedLong = localDateTimeAnnotatedLong;
}
public DateTime getDateTime() { public DateTime getDateTime() {
return dateTime; return dateTime;
} }

2
spring-jms/src/main/java/org/springframework/jms/support/converter/MappingJacksonMessageConverter.java

@ -38,7 +38,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
/** /**
* Message converter that uses the Jackson library to convert messages to and from JSON. * Message converter that uses Jackson 1.x to convert messages to and from JSON.
* Maps an object to a {@link BytesMessage}, or to a {@link TextMessage} if the * Maps an object to a {@link BytesMessage}, or to a {@link TextMessage} if the
* {@link #setTargetType targetType} is set to {@link MessageType#TEXT}. * {@link #setTargetType targetType} is set to {@link MessageType#TEXT}.
* Converts from a {@link TextMessage} or {@link BytesMessage} to an object. * Converts from a {@link TextMessage} or {@link BytesMessage} to an object.

34
spring-jms/src/test/java/org/springframework/jms/support/converter/MappingJacksonMessageConverterTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.springframework.jms.support.converter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -27,6 +28,7 @@ import javax.jms.TextMessage;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
@ -43,6 +45,7 @@ public class MappingJacksonMessageConverterTests {
private Session sessionMock; private Session sessionMock;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
sessionMock = mock(Session.class); sessionMock = mock(Session.class);
@ -51,22 +54,22 @@ public class MappingJacksonMessageConverterTests {
converter.setTypeIdPropertyName("__typeid__"); converter.setTypeIdPropertyName("__typeid__");
} }
@Test @Test
public void toBytesMessage() throws Exception { public void toBytesMessage() throws Exception {
BytesMessage bytesMessageMock = mock(BytesMessage.class); BytesMessage bytesMessageMock = mock(BytesMessage.class);
Object toBeMarshalled = new Object(); Date toBeMarshalled = new Date();
given(sessionMock.createBytesMessage()).willReturn(bytesMessageMock); given(sessionMock.createBytesMessage()).willReturn(bytesMessageMock);
converter.toMessage(toBeMarshalled, sessionMock); converter.toMessage(toBeMarshalled, sessionMock);
verify(bytesMessageMock).setStringProperty("__encoding__", "UTF-8"); verify(bytesMessageMock).setStringProperty("__encoding__", "UTF-8");
verify(bytesMessageMock).setStringProperty("__typeid__", Object.class.getName()); verify(bytesMessageMock).setStringProperty("__typeid__", Date.class.getName());
verify(bytesMessageMock).writeBytes(isA(byte[].class)); verify(bytesMessageMock).writeBytes(isA(byte[].class));
} }
@Test @Test
@SuppressWarnings("serial")
public void fromBytesMessage() throws Exception { public void fromBytesMessage() throws Exception {
BytesMessage bytesMessageMock = mock(BytesMessage.class); BytesMessage bytesMessageMock = mock(BytesMessage.class);
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar"); Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
@ -74,13 +77,11 @@ public class MappingJacksonMessageConverterTests {
byte[] bytes = "{\"foo\":\"bar\"}".getBytes(); byte[] bytes = "{\"foo\":\"bar\"}".getBytes();
final ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes); final ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
given(bytesMessageMock.getStringProperty("__typeid__")).willReturn( given(bytesMessageMock.getStringProperty("__typeid__")).willReturn(Object.class.getName());
Object.class.getName());
given(bytesMessageMock.propertyExists("__encoding__")).willReturn(false); given(bytesMessageMock.propertyExists("__encoding__")).willReturn(false);
given(bytesMessageMock.getBodyLength()).willReturn(new Long(bytes.length)); given(bytesMessageMock.getBodyLength()).willReturn(new Long(bytes.length));
given(bytesMessageMock.readBytes(any(byte[].class))).willAnswer( given(bytesMessageMock.readBytes(any(byte[].class))).willAnswer(
new Answer<Integer>() { new Answer<Integer>() {
@Override @Override
public Integer answer(InvocationOnMock invocation) throws Throwable { public Integer answer(InvocationOnMock invocation) throws Throwable {
return byteStream.read((byte[]) invocation.getArguments()[0]); return byteStream.read((byte[]) invocation.getArguments()[0]);
@ -95,13 +96,12 @@ public class MappingJacksonMessageConverterTests {
public void toTextMessageWithObject() throws Exception { public void toTextMessageWithObject() throws Exception {
converter.setTargetType(MessageType.TEXT); converter.setTargetType(MessageType.TEXT);
TextMessage textMessageMock = mock(TextMessage.class); TextMessage textMessageMock = mock(TextMessage.class);
Object toBeMarshalled = new Object(); Date toBeMarshalled = new Date();
given(sessionMock.createTextMessage(isA(String.class))).willReturn( given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
textMessageMock);
converter.toMessage(toBeMarshalled, sessionMock); converter.toMessage(toBeMarshalled, sessionMock);
verify(textMessageMock).setStringProperty("__typeid__", Object.class.getName()); verify(textMessageMock).setStringProperty("__typeid__", Date.class.getName());
} }
@Test @Test
@ -110,11 +110,10 @@ public class MappingJacksonMessageConverterTests {
TextMessage textMessageMock = mock(TextMessage.class); TextMessage textMessageMock = mock(TextMessage.class);
Map<String, String> toBeMarshalled = new HashMap<String, String>(); Map<String, String> toBeMarshalled = new HashMap<String, String>();
toBeMarshalled.put("foo", "bar"); toBeMarshalled.put("foo", "bar");
given(sessionMock.createTextMessage(isA(String.class))).willReturn(
textMessageMock);
converter.toMessage(toBeMarshalled, sessionMock); given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
converter.toMessage(toBeMarshalled, sessionMock);
verify(textMessageMock).setStringProperty("__typeid__", HashMap.class.getName()); verify(textMessageMock).setStringProperty("__typeid__", HashMap.class.getName());
} }
@ -124,8 +123,7 @@ public class MappingJacksonMessageConverterTests {
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar"); Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
String text = "{\"foo\":\"bar\"}"; String text = "{\"foo\":\"bar\"}";
given(textMessageMock.getStringProperty("__typeid__")).willReturn( given(textMessageMock.getStringProperty("__typeid__")).willReturn(Object.class.getName());
Object.class.getName());
given(textMessageMock.getText()).willReturn(text); given(textMessageMock.getText()).willReturn(text);
Object result = converter.fromMessage(textMessageMock); Object result = converter.fromMessage(textMessageMock);
@ -138,11 +136,11 @@ public class MappingJacksonMessageConverterTests {
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar"); Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
String text = "{\"foo\":\"bar\"}"; String text = "{\"foo\":\"bar\"}";
given(textMessageMock.getStringProperty("__typeid__")).willReturn( given(textMessageMock.getStringProperty("__typeid__")).willReturn(HashMap.class.getName());
HashMap.class.getName());
given(textMessageMock.getText()).willReturn(text); given(textMessageMock.getText()).willReturn(text);
Object result = converter.fromMessage(textMessageMock); Object result = converter.fromMessage(textMessageMock);
assertEquals("Invalid result", result, unmarshalled); assertEquals("Invalid result", result, unmarshalled);
} }
} }

36
spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonHttpMessageConverter.java

@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
@ -19,7 +19,6 @@ package org.springframework.http.converter.json;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.List;
import org.codehaus.jackson.JsonEncoding; import org.codehaus.jackson.JsonEncoding;
import org.codehaus.jackson.JsonGenerator; import org.codehaus.jackson.JsonGenerator;
@ -28,6 +27,7 @@ import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig; import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.type.TypeFactory; import org.codehaus.jackson.map.type.TypeFactory;
import org.codehaus.jackson.type.JavaType; import org.codehaus.jackson.type.JavaType;
import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage; import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
@ -38,13 +38,13 @@ import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter} * Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter} that
* that can read and write JSON using <a href="http://jackson.codehaus.org/">Jackson's</a> {@link ObjectMapper}. * can read and write JSON using <a href="http://jackson.codehaus.org/">Jackson 1.x's</a> {@link ObjectMapper}.
* *
* <p>This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances. * <p>This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances.
* *
* <p>By default, this converter supports {@code application/json}. This can be overridden by setting the * <p>By default, this converter supports {@code application/json}. This can be overridden by setting the
* {@link #setSupportedMediaTypes(List) supportedMediaTypes} property. * {@link #setSupportedMediaTypes supportedMediaTypes} property.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @since 3.0 * @since 3.0
@ -67,12 +67,14 @@ public class MappingJacksonHttpMessageConverter extends AbstractHttpMessageConve
* Construct a new {@code MappingJacksonHttpMessageConverter}. * Construct a new {@code MappingJacksonHttpMessageConverter}.
*/ */
public MappingJacksonHttpMessageConverter() { public MappingJacksonHttpMessageConverter() {
super(new MediaType("application", "json", DEFAULT_CHARSET), new MediaType("application", "*+json", DEFAULT_CHARSET)); super(new MediaType("application", "json", DEFAULT_CHARSET),
new MediaType("application", "*+json", DEFAULT_CHARSET));
} }
/** /**
* Set the {@code ObjectMapper} for this view. If not set, a default * Set the {@code ObjectMapper} for this view.
* {@link ObjectMapper#ObjectMapper() ObjectMapper} is used. * If not set, a default {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
* <p>Setting a custom-configured {@code ObjectMapper} is one way to take further control of the JSON * <p>Setting a custom-configured {@code ObjectMapper} is one way to take further control of the JSON
* serialization process. For example, an extended {@link org.codehaus.jackson.map.SerializerFactory} * serialization process. For example, an extended {@link org.codehaus.jackson.map.SerializerFactory}
* can be configured that provides custom serializers for specific types. The other option for refining * can be configured that provides custom serializers for specific types. The other option for refining
@ -85,12 +87,6 @@ public class MappingJacksonHttpMessageConverter extends AbstractHttpMessageConve
configurePrettyPrint(); configurePrettyPrint();
} }
private void configurePrettyPrint() {
if (this.prettyPrint != null) {
this.objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, this.prettyPrint);
}
}
/** /**
* Return the underlying {@code ObjectMapper} for this view. * Return the underlying {@code ObjectMapper} for this view.
*/ */
@ -122,7 +118,7 @@ public class MappingJacksonHttpMessageConverter extends AbstractHttpMessageConve
/** /**
* Whether to use the {@link org.codehaus.jackson.impl.DefaultPrettyPrinter} when writing JSON. * Whether to use the {@link org.codehaus.jackson.impl.DefaultPrettyPrinter} when writing JSON.
* This is a shortcut for setting up an {@code ObjectMapper} as follows: * This is a shortcut for setting up an {@code ObjectMapper} as follows:
* <pre> * <pre class="code">
* ObjectMapper mapper = new ObjectMapper(); * ObjectMapper mapper = new ObjectMapper();
* mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); * mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
* converter.setObjectMapper(mapper); * converter.setObjectMapper(mapper);
@ -134,6 +130,13 @@ public class MappingJacksonHttpMessageConverter extends AbstractHttpMessageConve
configurePrettyPrint(); configurePrettyPrint();
} }
private void configurePrettyPrint() {
if (this.prettyPrint != null) {
this.objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, this.prettyPrint);
}
}
@Override @Override
public boolean canRead(Class<?> clazz, MediaType mediaType) { public boolean canRead(Class<?> clazz, MediaType mediaType) {
return canRead(clazz, null, mediaType); return canRead(clazz, null, mediaType);
@ -226,8 +229,7 @@ public class MappingJacksonHttpMessageConverter extends AbstractHttpMessageConve
*/ */
protected JavaType getJavaType(Type type, Class<?> contextClass) { protected JavaType getJavaType(Type type, Class<?> contextClass) {
return (contextClass != null) ? return (contextClass != null) ?
TypeFactory.type(type, TypeFactory.type(contextClass)) : TypeFactory.type(type, TypeFactory.type(contextClass)) : TypeFactory.type(type);
TypeFactory.type(type);
} }
/** /**

23
spring-web/src/test/java/org/springframework/web/multipart/commons/CommonsMultipartResolverTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,10 +16,6 @@
package org.springframework.web.multipart.commons; package org.springframework.web.multipart.commons;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -34,7 +30,6 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
@ -44,9 +39,11 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileItemHeaders;
import org.apache.commons.fileupload.FileUpload; import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.MutablePropertyValues;
import org.springframework.mock.web.test.MockFilterConfig; import org.springframework.mock.web.test.MockFilterConfig;
import org.springframework.mock.web.test.MockHttpServletRequest; import org.springframework.mock.web.test.MockHttpServletRequest;
@ -64,6 +61,8 @@ import org.springframework.web.multipart.support.MultipartFilter;
import org.springframework.web.multipart.support.StringMultipartFileEditor; import org.springframework.web.multipart.support.StringMultipartFileEditor;
import org.springframework.web.util.WebUtils; import org.springframework.web.util.WebUtils;
import static org.junit.Assert.*;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Arjen Poutsma * @author Arjen Poutsma
@ -372,7 +371,7 @@ public class CommonsMultipartResolverTests {
protected FileUpload newFileUpload(FileItemFactory fileItemFactory) { protected FileUpload newFileUpload(FileItemFactory fileItemFactory) {
return new ServletFileUpload() { return new ServletFileUpload() {
@Override @Override
public List parseRequest(HttpServletRequest request) { public List<FileItem> parseRequest(HttpServletRequest request) {
if (request instanceof MultipartHttpServletRequest) { if (request instanceof MultipartHttpServletRequest) {
throw new IllegalStateException("Already a multipart request"); throw new IllegalStateException("Already a multipart request");
} }
@ -494,6 +493,16 @@ public class CommonsMultipartResolverTests {
public OutputStream getOutputStream() throws IOException { public OutputStream getOutputStream() throws IOException {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public FileItemHeaders getHeaders() {
throw new UnsupportedOperationException();
}
@Override
public void setHeaders(FileItemHeaders headers) {
throw new UnsupportedOperationException();
}
} }

2
spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJacksonJsonView.java

@ -39,7 +39,7 @@ import org.springframework.web.servlet.view.AbstractView;
/** /**
* Spring MVC {@link View} that renders JSON content by serializing the model for the current request * Spring MVC {@link View} that renders JSON content by serializing the model for the current request
* using <a href="http://jackson.codehaus.org/">Jackson's</a> {@link ObjectMapper}. * using <a href="http://jackson.codehaus.org/">Jackson 1.x's</a> {@link ObjectMapper}.
* *
* <p>By default, the entire contents of the model map (with the exception of framework-specific classes) * <p>By default, the entire contents of the model map (with the exception of framework-specific classes)
* will be encoded as JSON. If the model contains only one key, you can have it extracted encoded as JSON * will be encoded as JSON. If the model contains only one key, you can have it extracted encoded as JSON

71
spring-webmvc/src/test/java/org/springframework/web/servlet/view/json/MappingJacksonJsonViewTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -24,6 +24,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.codehaus.jackson.JsonGenerator; import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.BeanProperty;
import org.codehaus.jackson.map.JsonSerializer; import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig; import org.codehaus.jackson.map.SerializationConfig;
@ -31,18 +32,20 @@ import org.codehaus.jackson.map.SerializerFactory;
import org.codehaus.jackson.map.SerializerProvider; import org.codehaus.jackson.map.SerializerProvider;
import org.codehaus.jackson.map.annotate.JsonSerialize; import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.ser.BeanSerializerFactory; import org.codehaus.jackson.map.ser.BeanSerializerFactory;
import org.codehaus.jackson.type.JavaType;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mozilla.javascript.Context; import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory; import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.ScriptableObject;
import org.springframework.mock.web.test.MockHttpServletRequest; import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse; import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*; import static org.mockito.Mockito.*;
/** /**
* @author Jeremy Grelle * @author Jeremy Grelle
@ -60,17 +63,17 @@ public class MappingJacksonJsonViewTests {
private ScriptableObject jsScope; private ScriptableObject jsScope;
@Before @Before
public void setUp() { public void setUp() {
request = new MockHttpServletRequest(); request = new MockHttpServletRequest();
response = new MockHttpServletResponse(); response = new MockHttpServletResponse();
jsContext = ContextFactory.getGlobal().enterContext(); jsContext = ContextFactory.getGlobal().enterContext();
jsScope = jsContext.initStandardObjects(); jsScope = jsContext.initStandardObjects();
view = new MappingJacksonJsonView(); view = new MappingJacksonJsonView();
} }
@Test @Test
public void isExposePathVars() { public void isExposePathVars() {
assertEquals("Must not expose path variables", false, view.isExposePathVariables()); assertEquals("Must not expose path variables", false, view.isExposePathVariables());
@ -78,7 +81,6 @@ public class MappingJacksonJsonViewTests {
@Test @Test
public void renderSimpleMap() throws Exception { public void renderSimpleMap() throws Exception {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
model.put("bindingResult", mock(BindingResult.class, "binding_result")); model.put("bindingResult", mock(BindingResult.class, "binding_result"));
model.put("foo", "bar"); model.put("foo", "bar");
@ -89,13 +91,11 @@ public class MappingJacksonJsonViewTests {
assertEquals("no-cache", response.getHeader("Pragma")); assertEquals("no-cache", response.getHeader("Pragma"));
assertEquals("no-cache, no-store, max-age=0", response.getHeader("Cache-Control")); assertEquals("no-cache, no-store, max-age=0", response.getHeader("Cache-Control"));
assertNotNull(response.getHeader("Expires")); assertNotNull(response.getHeader("Expires"));
assertEquals(MappingJacksonJsonView.DEFAULT_CONTENT_TYPE, response.getContentType()); assertEquals(MappingJacksonJsonView.DEFAULT_CONTENT_TYPE, response.getContentType());
String jsonResult = response.getContentAsString(); String jsonResult = response.getContentAsString();
assertTrue(jsonResult.length() > 0); assertTrue(jsonResult.length() > 0);
assertEquals(jsonResult.length(), response.getContentLength()); assertEquals(jsonResult.length(), response.getContentLength());
validateResult(); validateResult();
} }
@ -106,7 +106,6 @@ public class MappingJacksonJsonViewTests {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
model.put("bindingResult", mock(BindingResult.class, "binding_result")); model.put("bindingResult", mock(BindingResult.class, "binding_result"));
model.put("foo", "bar"); model.put("foo", "bar");
view.render(model, request, response); view.render(model, request, response);
assertNull(response.getHeader("Pragma")); assertNull(response.getHeader("Pragma"));
@ -122,61 +121,58 @@ public class MappingJacksonJsonViewTests {
@Test @Test
public void renderSimpleBean() throws Exception { public void renderSimpleBean() throws Exception {
Object bean = new TestBeanSimple(); Object bean = new TestBeanSimple();
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
model.put("bindingResult", mock(BindingResult.class, "binding_result")); model.put("bindingResult", mock(BindingResult.class, "binding_result"));
model.put("foo", bean); model.put("foo", bean);
view.setUpdateContentLength(true); view.setUpdateContentLength(true);
view.render(model, request, response); view.render(model, request, response);
assertTrue(response.getContentAsString().length() > 0); assertTrue(response.getContentAsString().length() > 0);
assertEquals(response.getContentAsString().length(), response.getContentLength()); assertEquals(response.getContentAsString().length(), response.getContentLength());
validateResult(); validateResult();
} }
@Test @Test
public void renderWithPrettyPrint() throws Exception { public void renderWithPrettyPrint() throws Exception {
ModelMap model = new ModelMap("foo", new TestBeanSimple()); ModelMap model = new ModelMap("foo", new TestBeanSimple());
view.setPrettyPrint(true); view.setPrettyPrint(true);
view.render(model, request, response); view.render(model, request, response);
String result = response.getContentAsString().replace("\r\n", "\n"); String result = response.getContentAsString().replace("\r\n", "\n");
assertTrue("Pretty printing not applied:\n" + result, result.startsWith("{\n \"foo\" : {\n ")); assertTrue("Pretty printing not applied:\n" + result, result.startsWith("{\n \"foo\" : {\n "));
validateResult(); validateResult();
} }
@Test @Test
public void renderSimpleBeanPrefixed() throws Exception { public void renderSimpleBeanPrefixed() throws Exception {
view.setPrefixJson(true); view.setPrefixJson(true);
renderSimpleBean(); renderSimpleBean();
assertTrue(response.getContentAsString().startsWith("{} && "));
} }
@Test @Test
public void renderWithCustomSerializerLocatedByAnnotation() throws Exception { public void renderSimpleBeanNotPrefixed() throws Exception {
view.setPrefixJson(false);
renderSimpleBean();
assertFalse(response.getContentAsString().startsWith("{} && "));
}
@Test
public void renderWithCustomSerializerLocatedByAnnotation() throws Exception {
Object bean = new TestBeanSimpleAnnotated(); Object bean = new TestBeanSimpleAnnotated();
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
model.put("foo", bean); model.put("foo", bean);
view.render(model, request, response); view.render(model, request, response);
assertTrue(response.getContentAsString().length() > 0); assertTrue(response.getContentAsString().length() > 0);
assertEquals("{\"foo\":{\"testBeanSimple\":\"custom\"}}", response.getContentAsString()); assertEquals("{\"foo\":{\"testBeanSimple\":\"custom\"}}", response.getContentAsString());
validateResult(); validateResult();
} }
@Test @Test
public void renderWithCustomSerializerLocatedByFactory() throws Exception { public void renderWithCustomSerializerLocatedByFactory() throws Exception {
SerializerFactory factory = new DelegatingSerializerFactory(null);
SerializerFactory factory = new DelegatingSerializerFactory();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.setSerializerFactory(factory); mapper.setSerializerFactory(factory);
view.setObjectMapper(mapper); view.setObjectMapper(mapper);
@ -185,19 +181,16 @@ public class MappingJacksonJsonViewTests {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
model.put("foo", bean); model.put("foo", bean);
model.put("bar", new TestChildBean()); model.put("bar", new TestChildBean());
view.render(model, request, response); view.render(model, request, response);
String result = response.getContentAsString(); String result = response.getContentAsString();
assertTrue(result.length() > 0); assertTrue(result.length() > 0);
assertTrue(result.contains("\"foo\":{\"testBeanSimple\":\"custom\"}")); assertTrue(result.contains("\"foo\":{\"testBeanSimple\":\"custom\"}"));
validateResult(); validateResult();
} }
@Test @Test
public void renderOnlyIncludedAttributes() throws Exception { public void renderOnlyIncludedAttributes() throws Exception {
Set<String> attrs = new HashSet<String>(); Set<String> attrs = new HashSet<String>();
attrs.add("foo"); attrs.add("foo");
attrs.add("baz"); attrs.add("baz");
@ -208,14 +201,12 @@ public class MappingJacksonJsonViewTests {
model.put("foo", "foo"); model.put("foo", "foo");
model.put("bar", "bar"); model.put("bar", "bar");
model.put("baz", "baz"); model.put("baz", "baz");
view.render(model, request, response); view.render(model, request, response);
String result = response.getContentAsString(); String result = response.getContentAsString();
assertTrue(result.length() > 0); assertTrue(result.length() > 0);
assertTrue(result.contains("\"foo\":\"foo\"")); assertTrue(result.contains("\"foo\":\"foo\""));
assertTrue(result.contains("\"baz\":\"baz\"")); assertTrue(result.contains("\"baz\":\"baz\""));
validateResult(); validateResult();
} }
@ -226,7 +217,6 @@ public class MappingJacksonJsonViewTests {
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
TestBeanSimple bean = new TestBeanSimple(); TestBeanSimple bean = new TestBeanSimple();
model.put("foo", bean); model.put("foo", bean);
Object actual = view.filterModel(model); Object actual = view.filterModel(model);
assertSame(bean, actual); assertSame(bean, actual);
@ -288,11 +278,12 @@ public class MappingJacksonJsonViewTests {
} }
} }
@JsonSerialize(using=TestBeanSimpleSerializer.class)
public static class TestBeanSimpleAnnotated extends TestBeanSimple {
@JsonSerialize(using = TestBeanSimpleSerializer.class)
public static class TestBeanSimpleAnnotated extends TestBeanSimple {
} }
public static class TestChildBean { public static class TestChildBean {
private String value = "bar"; private String value = "bar";
@ -318,12 +309,11 @@ public class MappingJacksonJsonViewTests {
} }
} }
public static class TestBeanSimpleSerializer extends JsonSerializer<TestBeanSimple> {
@Override public static class TestBeanSimpleSerializer extends JsonSerializer<Object> {
public void serialize(TestBeanSimple value, JsonGenerator jgen, SerializerProvider provider)
throws IOException {
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartObject(); jgen.writeStartObject();
jgen.writeFieldName("testBeanSimple"); jgen.writeFieldName("testBeanSimple");
jgen.writeString("custom"); jgen.writeString("custom");
@ -332,19 +322,22 @@ public class MappingJacksonJsonViewTests {
} }
} }
public static class DelegatingSerializerFactory extends SerializerFactory {
private SerializerFactory delegate = BeanSerializerFactory.instance; public static class DelegatingSerializerFactory extends BeanSerializerFactory {
public DelegatingSerializerFactory(Config config) {
super(config);
}
@Override @Override
@SuppressWarnings("unchecked") public JsonSerializer<Object> createSerializer(SerializationConfig config, JavaType baseType, BeanProperty property) {
public <T> JsonSerializer<T> createSerializer(Class<T> type, SerializationConfig config) { if (baseType.getRawClass() == TestBeanSimple.class) {
if (type == TestBeanSimple.class) { return new TestBeanSimpleSerializer();
return (JsonSerializer<T>) new TestBeanSimpleSerializer();
} }
else { else {
return delegate.createSerializer(type, config); return super.createSerializer(config, baseType, property);
} }
} }
} }
} }

Loading…
Cancel
Save