diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.java
index 6e29331036..e0b9c1dbe0 100644
--- a/spring-web/src/main/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.java
+++ b/spring-web/src/main/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2013 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.
@@ -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 com.fasterxml.jackson.core.JsonEncoding;
import com.fasterxml.jackson.core.JsonGenerator;
@@ -45,13 +44,14 @@ import org.springframework.util.Assert;
*
This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances.
*
*
By default, this converter supports {@code application/json}. This can be overridden by setting the
- * {@link #setSupportedMediaTypes(List) supportedMediaTypes} property.
+ * {@link #setSupportedMediaTypes supportedMediaTypes} property.
+ *
+ *
Tested against Jackson 2.2; compatible with Jackson 2.0 and higher.
*
* @author Arjen Poutsma
* @author Keith Donald
* @author Rossen Stoyanchev
* @since 3.1.2
- * @see org.springframework.web.servlet.view.json.MappingJackson2JsonView
*/
public class MappingJackson2HttpMessageConverter extends AbstractHttpMessageConverter
implements GenericHttpMessageConverter {
@@ -70,12 +70,14 @@ public class MappingJackson2HttpMessageConverter extends AbstractHttpMessageConv
* Construct a new {@code MappingJackson2HttpMessageConverter}.
*/
public MappingJackson2HttpMessageConverter() {
- 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.
* 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
@@ -88,12 +90,6 @@ public class MappingJackson2HttpMessageConverter extends AbstractHttpMessageConv
configurePrettyPrint();
}
- private void configurePrettyPrint() {
- if (this.prettyPrint != null) {
- this.objectMapper.configure(SerializationFeature.INDENT_OUTPUT, this.prettyPrint);
- }
- }
-
/**
* Return the underlying {@code ObjectMapper} for this view.
*/
@@ -126,6 +122,12 @@ public class MappingJackson2HttpMessageConverter extends AbstractHttpMessageConv
configurePrettyPrint();
}
+ private void configurePrettyPrint() {
+ if (this.prettyPrint != null) {
+ this.objectMapper.configure(SerializationFeature.INDENT_OUTPUT, this.prettyPrint);
+ }
+ }
+
@Override
public boolean canRead(Class> clazz, MediaType mediaType) {
@@ -172,7 +174,6 @@ public class MappingJackson2HttpMessageConverter extends AbstractHttpMessageConv
}
}
-
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage)
throws IOException, HttpMessageNotWritableException {
@@ -180,6 +181,7 @@ public class MappingJackson2HttpMessageConverter extends AbstractHttpMessageConv
JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
// The following has been deprecated as late as Jackson 2.2 (April 2013);
// preserved for the time being, for Jackson 2.0/2.1 compatibility.
+ @SuppressWarnings("deprecation")
JsonGenerator jsonGenerator =
this.objectMapper.getJsonFactory().createJsonGenerator(outputMessage.getBody(), encoding);
diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonHttpMessageConverter.java
index 38716e1893..0a33145404 100644
--- a/spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonHttpMessageConverter.java
+++ b/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 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;
@@ -44,11 +43,13 @@ import org.springframework.util.Assert;
*
This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances.
*
*
By default, this converter supports {@code application/json}. This can be overridden by setting the
- * {@link #setSupportedMediaTypes(List) supportedMediaTypes} property.
+ * {@link #setSupportedMediaTypes supportedMediaTypes} property.
+ *
+ *
NOTE: Requires Jackson 1.8 or higher, as of Spring 4.0.
*
* @author Arjen Poutsma
+ * @author Juergen Hoeller
* @since 3.0
- * @see org.springframework.web.servlet.view.json.MappingJacksonJsonView
*/
public class MappingJacksonHttpMessageConverter extends AbstractHttpMessageConverter
implements GenericHttpMessageConverter {
@@ -67,12 +68,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.
* 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 +88,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.
*/
@@ -124,6 +121,12 @@ 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) {
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java
index 67bfe1174b..115935fa89 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java
@@ -42,15 +42,14 @@ import org.springframework.web.servlet.view.AbstractView;
* using Jackson 2.x's {@link ObjectMapper}.
*
*
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
- * alone via {@link #setExtractValueFromSingleKeyModel}.
+ * will be encoded as JSON. If the model contains only one key, you can have it extracted encoded as
+ * JSON alone via {@link #setExtractValueFromSingleKeyModel}.
*
* @author Jeremy Grelle
* @author Arjen Poutsma
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @since 3.1.2
- * @see org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
*/
public class MappingJackson2JsonView extends AbstractView {
@@ -280,6 +279,7 @@ public class MappingJackson2JsonView extends AbstractView {
protected void writeContent(OutputStream stream, Object value, boolean prefixJson) throws IOException {
// The following has been deprecated as late as Jackson 2.2 (April 2013);
// preserved for the time being, for Jackson 2.0/2.1 compatibility.
+ @SuppressWarnings("deprecation")
JsonGenerator generator = this.objectMapper.getJsonFactory().createJsonGenerator(stream, this.encoding);
// A workaround for JsonGenerators not applying serialization features
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJacksonJsonView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJacksonJsonView.java
index 1b8e0890a6..baa727d8c0 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJacksonJsonView.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJacksonJsonView.java
@@ -42,15 +42,14 @@ import org.springframework.web.servlet.view.AbstractView;
* using Jackson 1.x's {@link ObjectMapper}.
*
*
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
- * alone via {@link #setExtractValueFromSingleKeyModel}.
+ * will be encoded as JSON. If the model contains only one key, you can have it extracted encoded as
+ * JSON alone via {@link #setExtractValueFromSingleKeyModel}.
*
* @author Jeremy Grelle
* @author Arjen Poutsma
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @since 3.0
- * @see org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
*/
public class MappingJacksonJsonView extends AbstractView {