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 80f9b430a3d..43f2eba97fb 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-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,14 +24,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.http.MediaType; /** - * Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter} that - * can read and write JSON using Jackson 2.x's {@link ObjectMapper}. + * Implementation of {@link org.springframework.http.converter.HttpMessageConverter} that can read and + * write JSON using Jackson 2.x's {@link ObjectMapper}. * - *

This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances. + *

This converter can be used to bind to typed beans, or untyped {@code HashMap} instances. * *

By default, this converter supports {@code application/json} and {@code application/*+json} - * with {@code UTF-8} character set. - * This can be overridden by setting the {@link #setSupportedMediaTypes supportedMediaTypes} property. + * with {@code UTF-8} character set. This can be overridden by setting the + * {@link #setSupportedMediaTypes supportedMediaTypes} property. * *

The default constructor uses the default configuration provided by {@link Jackson2ObjectMapperBuilder}. * diff --git a/spring-web/src/main/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverter.java index f6099585cc2..2f5aaffc103 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/xml/MappingJackson2XmlHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,8 @@ import org.springframework.util.Assert; * Jackson 2.x extension component for reading and writing XML encoded data. * *

By default, this converter supports {@code application/xml}, {@code text/xml}, and - * {@code application/*+xml} with {@code UTF-8} character set. - * This can be overridden by setting the {@link #setSupportedMediaTypes(java.util.List) supportedMediaTypes} property. + * {@code application/*+xml} with {@code UTF-8} character set. This can be overridden by + * setting the {@link #setSupportedMediaTypes supportedMediaTypes} property. * *

The default constructor uses the default configuration provided by {@link Jackson2ObjectMapperBuilder}. * @@ -72,4 +72,5 @@ public class MappingJackson2XmlHttpMessageConverter extends AbstractJackson2Http Assert.isAssignable(XmlMapper.class, objectMapper.getClass()); super.setObjectMapper(objectMapper); } + } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/AbstractJackson2View.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/AbstractJackson2View.java index 2069bbcd607..34b75fa2fd6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/AbstractJackson2View.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/AbstractJackson2View.java @@ -122,12 +122,6 @@ public abstract class AbstractJackson2View extends AbstractView { } } - /** - * Set the attribute in the model that should be rendered by this view. - * When set, all other model attributes will be ignored. - */ - public abstract void setModelKey(String modelKey); - /** * Disables caching of the generated JSON. *

Default is {@code true}, which will prevent the client from caching the generated JSON. @@ -187,23 +181,13 @@ public abstract class AbstractJackson2View extends AbstractView { return value; } - /** - * Filter out undesired attributes from the given model. - * The return value can be either another {@link Map} or a single value object. - * @param model the model, as passed on to {@link #renderMergedOutputModel} - * @return the value to be rendered - */ - protected abstract Object filterModel(Map model); - /** * Write the actual JSON content to the stream. * @param stream the output stream to use * @param object the value to be rendered, as returned from {@link #filterModel} * @throws IOException if writing failed */ - protected void writeContent(OutputStream stream, Object object) - throws IOException { - + protected void writeContent(OutputStream stream, Object object) throws IOException { JsonGenerator generator = this.objectMapper.getFactory().createGenerator(stream, this.encoding); writePrefix(generator, object); @@ -230,13 +214,27 @@ public abstract class AbstractJackson2View extends AbstractView { generator.flush(); } + + /** + * Set the attribute in the model that should be rendered by this view. + * When set, all other model attributes will be ignored. + */ + public abstract void setModelKey(String modelKey); + + /** + * Filter out undesired attributes from the given model. + * The return value can be either another {@link Map} or a single value object. + * @param model the model, as passed on to {@link #renderMergedOutputModel} + * @return the value to be rendered + */ + protected abstract Object filterModel(Map model); + /** * Write a prefix before the main content. * @param generator the generator to use for writing content. * @param object the object to write to the output message. */ protected void writePrefix(JsonGenerator generator, Object object) throws IOException { - } /** @@ -245,7 +243,6 @@ public abstract class AbstractJackson2View extends AbstractView { * @param object the object to write to the output message. */ protected void writeSuffix(JsonGenerator generator, Object object) throws IOException { - } }