Upgraded to Commons FileUpload 1.3.1, TestNG 6.8.7, Hibernate 4.2.8, Joda-Time 2.2, Jackson 1.7.9
This commit is contained in:
40
build.gradle
40
build.gradle
@@ -17,7 +17,7 @@ configure(allprojects) { project ->
|
||||
// "Class not found: javac1.8" issue with Ant versions prior to 1.9.x
|
||||
ant.properties["build.compiler"] = "javac1.7"
|
||||
|
||||
ext.aspectjVersion = "1.7.2"
|
||||
ext.aspectjVersion = "1.7.4"
|
||||
ext.hsqldbVersion = "1.8.0.10"
|
||||
ext.junitVersion = "4.11"
|
||||
ext.slf4jVersion = "1.6.6"
|
||||
@@ -328,11 +328,11 @@ project("spring-context") {
|
||||
optional("javax.persistence:persistence-api:1.0")
|
||||
optional("javax.validation:validation-api:1.0.0.GA")
|
||||
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.codehaus.groovy:groovy-all:1.8.9")
|
||||
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("commons-dbcp:commons-dbcp:1.3")
|
||||
testCompile("org.slf4j:slf4j-api:${slf4jVersion}")
|
||||
@@ -406,7 +406,7 @@ project("spring-jms") {
|
||||
optional("aopalliance:aopalliance:1.0")
|
||||
optional("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1")
|
||||
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")
|
||||
}
|
||||
}
|
||||
@@ -444,7 +444,7 @@ project("spring-context-support") {
|
||||
optional("org.quartz-scheduler:quartz:1.7.3")
|
||||
optional("org.codehaus.fabric3.api:commonj:1.1.0")
|
||||
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("jasperreports:jasperreports:2.0.5")
|
||||
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("aopalliance:aopalliance:1.0")
|
||||
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-httpclient:commons-httpclient:3.1")
|
||||
optional("org.apache.httpcomponents:httpclient:4.2")
|
||||
optional("org.codehaus.jackson:jackson-mapper-asl:1.4.5")
|
||||
optional("org.apache.httpcomponents:httpclient:4.2.6")
|
||||
optional("org.codehaus.jackson:jackson-mapper-asl:1.7.9")
|
||||
optional("com.fasterxml.jackson.core:jackson-databind:2.0.6")
|
||||
optional("rome:rome:1.0")
|
||||
optional("taglibs:standard:1.1.2")
|
||||
@@ -547,8 +547,8 @@ project("spring-orm-hibernate4") {
|
||||
provided(project(":spring-jdbc"))
|
||||
provided(project(":spring-tx"))
|
||||
optional(project(":spring-web"))
|
||||
optional("org.hibernate:hibernate-core:4.1.9.Final")
|
||||
optional("org.hibernate:hibernate-entitymanager:4.1.9.Final")
|
||||
optional("org.hibernate:hibernate-core:4.2.8.Final")
|
||||
optional("org.hibernate:hibernate-entitymanager:4.2.8.Final")
|
||||
optional("javax.servlet:servlet-api:2.5")
|
||||
}
|
||||
}
|
||||
@@ -567,16 +567,16 @@ project("spring-webmvc") {
|
||||
optional(project(":spring-oxm")) // for MarshallingView
|
||||
optional("javax.servlet.jsp:jsp-api:2.1")
|
||||
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("velocity:velocity:1.5")
|
||||
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("jasperreports:jasperreports:2.0.5") {
|
||||
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("rome:rome:1.0")
|
||||
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("org.hibernate:hibernate-validator:4.3.1.Final")
|
||||
testCompile("org.apache.httpcomponents:httpclient:4.2")
|
||||
testCompile("commons-fileupload:commons-fileupload:1.2.2")
|
||||
testCompile("org.apache.httpcomponents:httpclient:4.2.6")
|
||||
testCompile("commons-fileupload:commons-fileupload:1.3.1")
|
||||
testCompile("commons-io:commons-io:1.3")
|
||||
testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
|
||||
}
|
||||
@@ -656,7 +656,7 @@ project("spring-webmvc-portlet") {
|
||||
compile(project(":spring-webmvc"))
|
||||
provided("javax.servlet:servlet-api:2.5")
|
||||
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
|
||||
@@ -678,7 +678,7 @@ project("spring-test") {
|
||||
optional(project(":spring-webmvc"))
|
||||
optional(project(":spring-webmvc-portlet"))
|
||||
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.servlet:servlet-api:2.5")
|
||||
optional("javax.servlet.jsp:jsp-api:2.1")
|
||||
@@ -732,7 +732,7 @@ project("spring-test-mvc") {
|
||||
testCompile("javax.mail:mail:1.4.7")
|
||||
testCompile("org.hibernate:hibernate-validator:4.3.1.Final")
|
||||
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("rome:rome:1.0")
|
||||
testCompile("org.apache.tiles:tiles-request-api:1.0.1")
|
||||
@@ -865,7 +865,7 @@ configure(rootProject) {
|
||||
testCompile("javax.inject:javax.inject:1")
|
||||
testCompile("javax.resource:connector-api:1.5")
|
||||
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}")
|
||||
}
|
||||
|
||||
@@ -899,7 +899,7 @@ configure(rootProject) {
|
||||
|
||||
doFirst {
|
||||
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
|
||||
project(":spring-webmvc").sourceSets.main.compileClasspath.files.find { it =~ "servlet-api" },
|
||||
rootProject.sourceSets.test.compileClasspath.files.find { it =~ "hibernate-core" },
|
||||
|
||||
@@ -16,11 +16,6 @@
|
||||
|
||||
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.Calendar;
|
||||
import java.util.Date;
|
||||
@@ -37,6 +32,7 @@ import org.joda.time.MutableDateTime;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
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.validation.DataBinder;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Keith Donald
|
||||
* @author Juergen Hoeller
|
||||
@@ -236,21 +235,10 @@ public class JodaTimeFormattingTests {
|
||||
@Test
|
||||
public void testBindLocalDateTimeAnnotated() {
|
||||
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);
|
||||
assertEquals(0, binder.getBindingResult().getErrorCount());
|
||||
assertEquals("Saturday, October 31, 2009 12:00:00 PM ", binder.getBindingResult().getFieldValue(
|
||||
"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"));
|
||||
assertEquals("Oct 31, 2009 12:00 PM", binder.getBindingResult().getFieldValue("localDateTimeAnnotated"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -510,12 +498,9 @@ public class JodaTimeFormattingTests {
|
||||
|
||||
private LocalDateTime localDateTime;
|
||||
|
||||
@DateTimeFormat(style="FF")
|
||||
@DateTimeFormat(style="MS")
|
||||
private LocalDateTime localDateTimeAnnotated;
|
||||
|
||||
@DateTimeFormat(style="LL")
|
||||
private LocalDateTime localDateTimeAnnotatedLong;
|
||||
|
||||
private DateTime dateTime;
|
||||
|
||||
@DateTimeFormat(style="MS")
|
||||
@@ -612,14 +597,6 @@ public class JodaTimeFormattingTests {
|
||||
this.localDateTimeAnnotated = localDateTimeAnnotated;
|
||||
}
|
||||
|
||||
public LocalDateTime getLocalDateTimeAnnotatedLong() {
|
||||
return localDateTimeAnnotatedLong;
|
||||
}
|
||||
|
||||
public void setLocalDateTimeAnnotatedLong(LocalDateTime localDateTimeAnnotatedLong) {
|
||||
this.localDateTimeAnnotatedLong = localDateTimeAnnotatedLong;
|
||||
}
|
||||
|
||||
public DateTime getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.util.Assert;
|
||||
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
|
||||
* {@link #setTargetType targetType} is set to {@link MessageType#TEXT}.
|
||||
* Converts from a {@link TextMessage} or {@link BytesMessage} to an object.
|
||||
|
||||
@@ -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");
|
||||
* 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.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -27,6 +28,7 @@ import javax.jms.TextMessage;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
@@ -43,6 +45,7 @@ public class MappingJacksonMessageConverterTests {
|
||||
|
||||
private Session sessionMock;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
sessionMock = mock(Session.class);
|
||||
@@ -51,22 +54,22 @@ public class MappingJacksonMessageConverterTests {
|
||||
converter.setTypeIdPropertyName("__typeid__");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void toBytesMessage() throws Exception {
|
||||
BytesMessage bytesMessageMock = mock(BytesMessage.class);
|
||||
Object toBeMarshalled = new Object();
|
||||
Date toBeMarshalled = new Date();
|
||||
|
||||
given(sessionMock.createBytesMessage()).willReturn(bytesMessageMock);
|
||||
|
||||
converter.toMessage(toBeMarshalled, sessionMock);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("serial")
|
||||
public void fromBytesMessage() throws Exception {
|
||||
BytesMessage bytesMessageMock = mock(BytesMessage.class);
|
||||
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
|
||||
@@ -74,13 +77,11 @@ public class MappingJacksonMessageConverterTests {
|
||||
byte[] bytes = "{\"foo\":\"bar\"}".getBytes();
|
||||
final ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
|
||||
|
||||
given(bytesMessageMock.getStringProperty("__typeid__")).willReturn(
|
||||
Object.class.getName());
|
||||
given(bytesMessageMock.getStringProperty("__typeid__")).willReturn(Object.class.getName());
|
||||
given(bytesMessageMock.propertyExists("__encoding__")).willReturn(false);
|
||||
given(bytesMessageMock.getBodyLength()).willReturn(new Long(bytes.length));
|
||||
given(bytesMessageMock.readBytes(any(byte[].class))).willAnswer(
|
||||
new Answer<Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer answer(InvocationOnMock invocation) throws Throwable {
|
||||
return byteStream.read((byte[]) invocation.getArguments()[0]);
|
||||
@@ -95,13 +96,12 @@ public class MappingJacksonMessageConverterTests {
|
||||
public void toTextMessageWithObject() throws Exception {
|
||||
converter.setTargetType(MessageType.TEXT);
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
Object toBeMarshalled = new Object();
|
||||
Date toBeMarshalled = new Date();
|
||||
|
||||
given(sessionMock.createTextMessage(isA(String.class))).willReturn(
|
||||
textMessageMock);
|
||||
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
|
||||
|
||||
converter.toMessage(toBeMarshalled, sessionMock);
|
||||
verify(textMessageMock).setStringProperty("__typeid__", Object.class.getName());
|
||||
verify(textMessageMock).setStringProperty("__typeid__", Date.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,11 +110,10 @@ public class MappingJacksonMessageConverterTests {
|
||||
TextMessage textMessageMock = mock(TextMessage.class);
|
||||
Map<String, String> toBeMarshalled = new HashMap<String, String>();
|
||||
toBeMarshalled.put("foo", "bar");
|
||||
given(sessionMock.createTextMessage(isA(String.class))).willReturn(
|
||||
textMessageMock);
|
||||
|
||||
given(sessionMock.createTextMessage(isA(String.class))).willReturn(textMessageMock);
|
||||
|
||||
converter.toMessage(toBeMarshalled, sessionMock);
|
||||
|
||||
verify(textMessageMock).setStringProperty("__typeid__", HashMap.class.getName());
|
||||
}
|
||||
|
||||
@@ -124,8 +123,7 @@ public class MappingJacksonMessageConverterTests {
|
||||
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
|
||||
|
||||
String text = "{\"foo\":\"bar\"}";
|
||||
given(textMessageMock.getStringProperty("__typeid__")).willReturn(
|
||||
Object.class.getName());
|
||||
given(textMessageMock.getStringProperty("__typeid__")).willReturn(Object.class.getName());
|
||||
given(textMessageMock.getText()).willReturn(text);
|
||||
|
||||
Object result = converter.fromMessage(textMessageMock);
|
||||
@@ -138,11 +136,11 @@ public class MappingJacksonMessageConverterTests {
|
||||
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
|
||||
|
||||
String text = "{\"foo\":\"bar\"}";
|
||||
given(textMessageMock.getStringProperty("__typeid__")).willReturn(
|
||||
HashMap.class.getName());
|
||||
given(textMessageMock.getStringProperty("__typeid__")).willReturn(HashMap.class.getName());
|
||||
given(textMessageMock.getText()).willReturn(text);
|
||||
|
||||
Object result = converter.fromMessage(textMessageMock);
|
||||
assertEquals("Invalid result", result, unmarshalled);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* 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
|
||||
* 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,
|
||||
@@ -19,7 +19,6 @@ package org.springframework.http.converter.json;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
|
||||
import org.codehaus.jackson.JsonEncoding;
|
||||
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.type.TypeFactory;
|
||||
import org.codehaus.jackson.type.JavaType;
|
||||
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -38,13 +38,13 @@ import org.springframework.http.converter.HttpMessageNotWritableException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter}
|
||||
* that can read and write JSON using <a href="http://jackson.codehaus.org/">Jackson's</a> {@link ObjectMapper}.
|
||||
* Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter} that
|
||||
* 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>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
|
||||
* @since 3.0
|
||||
@@ -67,12 +67,14 @@ public class MappingJacksonHttpMessageConverter extends AbstractHttpMessageConve
|
||||
* Construct a new {@code 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
|
||||
* {@link ObjectMapper#ObjectMapper() ObjectMapper} is used.
|
||||
* Set the {@code ObjectMapper} for this view.
|
||||
* 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
|
||||
* 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
|
||||
@@ -85,12 +87,6 @@ public class MappingJacksonHttpMessageConverter extends AbstractHttpMessageConve
|
||||
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.
|
||||
*/
|
||||
@@ -122,7 +118,7 @@ public class MappingJacksonHttpMessageConverter extends AbstractHttpMessageConve
|
||||
/**
|
||||
* 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:
|
||||
* <pre>
|
||||
* <pre class="code">
|
||||
* ObjectMapper mapper = new ObjectMapper();
|
||||
* mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
|
||||
* converter.setObjectMapper(mapper);
|
||||
@@ -134,6 +130,13 @@ public class MappingJacksonHttpMessageConverter extends AbstractHttpMessageConve
|
||||
configurePrettyPrint();
|
||||
}
|
||||
|
||||
private void configurePrettyPrint() {
|
||||
if (this.prettyPrint != null) {
|
||||
this.objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, this.prettyPrint);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canRead(Class<?> clazz, MediaType mediaType) {
|
||||
return canRead(clazz, null, mediaType);
|
||||
@@ -226,8 +229,7 @@ public class MappingJacksonHttpMessageConverter extends AbstractHttpMessageConve
|
||||
*/
|
||||
protected JavaType getJavaType(Type type, Class<?> contextClass) {
|
||||
return (contextClass != null) ?
|
||||
TypeFactory.type(type, TypeFactory.type(contextClass)) :
|
||||
TypeFactory.type(type);
|
||||
TypeFactory.type(type, TypeFactory.type(contextClass)) : TypeFactory.type(type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,6 @@
|
||||
|
||||
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.File;
|
||||
import java.io.IOException;
|
||||
@@ -34,7 +30,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
@@ -44,9 +39,11 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileItemFactory;
|
||||
import org.apache.commons.fileupload.FileItemHeaders;
|
||||
import org.apache.commons.fileupload.FileUpload;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.mock.web.test.MockFilterConfig;
|
||||
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.util.WebUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Arjen Poutsma
|
||||
@@ -372,7 +371,7 @@ public class CommonsMultipartResolverTests {
|
||||
protected FileUpload newFileUpload(FileItemFactory fileItemFactory) {
|
||||
return new ServletFileUpload() {
|
||||
@Override
|
||||
public List parseRequest(HttpServletRequest request) {
|
||||
public List<FileItem> parseRequest(HttpServletRequest request) {
|
||||
if (request instanceof MultipartHttpServletRequest) {
|
||||
throw new IllegalStateException("Already a multipart request");
|
||||
}
|
||||
@@ -494,6 +493,16 @@ public class CommonsMultipartResolverTests {
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileItemHeaders getHeaders() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaders(FileItemHeaders headers) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
* 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)
|
||||
* will be encoded as JSON. If the model contains only one key, you can have it extracted encoded as JSON
|
||||
|
||||
@@ -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");
|
||||
* 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 org.codehaus.jackson.JsonGenerator;
|
||||
import org.codehaus.jackson.map.BeanProperty;
|
||||
import org.codehaus.jackson.map.JsonSerializer;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
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.annotate.JsonSerialize;
|
||||
import org.codehaus.jackson.map.ser.BeanSerializerFactory;
|
||||
import org.codehaus.jackson.type.JavaType;
|
||||
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.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* @author Jeremy Grelle
|
||||
@@ -60,17 +63,17 @@ public class MappingJacksonJsonViewTests {
|
||||
|
||||
private ScriptableObject jsScope;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
|
||||
jsContext = ContextFactory.getGlobal().enterContext();
|
||||
jsScope = jsContext.initStandardObjects();
|
||||
|
||||
view = new MappingJacksonJsonView();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void isExposePathVars() {
|
||||
assertEquals("Must not expose path variables", false, view.isExposePathVariables());
|
||||
@@ -78,7 +81,6 @@ public class MappingJacksonJsonViewTests {
|
||||
|
||||
@Test
|
||||
public void renderSimpleMap() throws Exception {
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("bindingResult", mock(BindingResult.class, "binding_result"));
|
||||
model.put("foo", "bar");
|
||||
@@ -89,13 +91,11 @@ public class MappingJacksonJsonViewTests {
|
||||
assertEquals("no-cache", response.getHeader("Pragma"));
|
||||
assertEquals("no-cache, no-store, max-age=0", response.getHeader("Cache-Control"));
|
||||
assertNotNull(response.getHeader("Expires"));
|
||||
|
||||
assertEquals(MappingJacksonJsonView.DEFAULT_CONTENT_TYPE, response.getContentType());
|
||||
|
||||
String jsonResult = response.getContentAsString();
|
||||
assertTrue(jsonResult.length() > 0);
|
||||
assertEquals(jsonResult.length(), response.getContentLength());
|
||||
|
||||
validateResult();
|
||||
}
|
||||
|
||||
@@ -106,7 +106,6 @@ public class MappingJacksonJsonViewTests {
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("bindingResult", mock(BindingResult.class, "binding_result"));
|
||||
model.put("foo", "bar");
|
||||
|
||||
view.render(model, request, response);
|
||||
|
||||
assertNull(response.getHeader("Pragma"));
|
||||
@@ -122,61 +121,58 @@ public class MappingJacksonJsonViewTests {
|
||||
|
||||
@Test
|
||||
public void renderSimpleBean() throws Exception {
|
||||
|
||||
Object bean = new TestBeanSimple();
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("bindingResult", mock(BindingResult.class, "binding_result"));
|
||||
model.put("foo", bean);
|
||||
|
||||
view.setUpdateContentLength(true);
|
||||
view.render(model, request, response);
|
||||
|
||||
assertTrue(response.getContentAsString().length() > 0);
|
||||
assertEquals(response.getContentAsString().length(), response.getContentLength());
|
||||
|
||||
validateResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderWithPrettyPrint() throws Exception {
|
||||
|
||||
ModelMap model = new ModelMap("foo", new TestBeanSimple());
|
||||
|
||||
view.setPrettyPrint(true);
|
||||
view.render(model, request, response);
|
||||
|
||||
String result = response.getContentAsString().replace("\r\n", "\n");
|
||||
assertTrue("Pretty printing not applied:\n" + result, result.startsWith("{\n \"foo\" : {\n "));
|
||||
|
||||
validateResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderSimpleBeanPrefixed() throws Exception {
|
||||
|
||||
view.setPrefixJson(true);
|
||||
renderSimpleBean();
|
||||
assertTrue(response.getContentAsString().startsWith("{} && "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderSimpleBeanNotPrefixed() throws Exception {
|
||||
view.setPrefixJson(false);
|
||||
renderSimpleBean();
|
||||
assertFalse(response.getContentAsString().startsWith("{} && "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderWithCustomSerializerLocatedByAnnotation() throws Exception {
|
||||
|
||||
Object bean = new TestBeanSimpleAnnotated();
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("foo", bean);
|
||||
|
||||
view.render(model, request, response);
|
||||
|
||||
assertTrue(response.getContentAsString().length() > 0);
|
||||
assertEquals("{\"foo\":{\"testBeanSimple\":\"custom\"}}", response.getContentAsString());
|
||||
|
||||
validateResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderWithCustomSerializerLocatedByFactory() throws Exception {
|
||||
|
||||
SerializerFactory factory = new DelegatingSerializerFactory();
|
||||
SerializerFactory factory = new DelegatingSerializerFactory(null);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setSerializerFactory(factory);
|
||||
view.setObjectMapper(mapper);
|
||||
@@ -185,19 +181,16 @@ public class MappingJacksonJsonViewTests {
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("foo", bean);
|
||||
model.put("bar", new TestChildBean());
|
||||
|
||||
view.render(model, request, response);
|
||||
|
||||
String result = response.getContentAsString();
|
||||
assertTrue(result.length() > 0);
|
||||
assertTrue(result.contains("\"foo\":{\"testBeanSimple\":\"custom\"}"));
|
||||
|
||||
validateResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderOnlyIncludedAttributes() throws Exception {
|
||||
|
||||
Set<String> attrs = new HashSet<String>();
|
||||
attrs.add("foo");
|
||||
attrs.add("baz");
|
||||
@@ -208,14 +201,12 @@ public class MappingJacksonJsonViewTests {
|
||||
model.put("foo", "foo");
|
||||
model.put("bar", "bar");
|
||||
model.put("baz", "baz");
|
||||
|
||||
view.render(model, request, response);
|
||||
|
||||
String result = response.getContentAsString();
|
||||
assertTrue(result.length() > 0);
|
||||
assertTrue(result.contains("\"foo\":\"foo\""));
|
||||
assertTrue(result.contains("\"baz\":\"baz\""));
|
||||
|
||||
validateResult();
|
||||
}
|
||||
|
||||
@@ -226,7 +217,6 @@ public class MappingJacksonJsonViewTests {
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
TestBeanSimple bean = new TestBeanSimple();
|
||||
model.put("foo", bean);
|
||||
|
||||
Object actual = view.filterModel(model);
|
||||
|
||||
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 {
|
||||
|
||||
private String value = "bar";
|
||||
@@ -318,12 +309,11 @@ public class MappingJacksonJsonViewTests {
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestBeanSimpleSerializer extends JsonSerializer<TestBeanSimple> {
|
||||
|
||||
public static class TestBeanSimpleSerializer extends JsonSerializer<Object> {
|
||||
|
||||
@Override
|
||||
public void serialize(TestBeanSimple value, JsonGenerator jgen, SerializerProvider provider)
|
||||
throws IOException {
|
||||
|
||||
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
|
||||
jgen.writeStartObject();
|
||||
jgen.writeFieldName("testBeanSimple");
|
||||
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
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> JsonSerializer<T> createSerializer(Class<T> type, SerializationConfig config) {
|
||||
if (type == TestBeanSimple.class) {
|
||||
return (JsonSerializer<T>) new TestBeanSimpleSerializer();
|
||||
public JsonSerializer<Object> createSerializer(SerializationConfig config, JavaType baseType, BeanProperty property) {
|
||||
if (baseType.getRawClass() == TestBeanSimple.class) {
|
||||
return new TestBeanSimpleSerializer();
|
||||
}
|
||||
else {
|
||||
return delegate.createSerializer(type, config);
|
||||
return super.createSerializer(config, baseType, property);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user