SPR-6340 - Add coverage of JSON support to reference guide
This commit is contained in:
parent
a5be9c5cf5
commit
e8845c7ead
|
@ -2151,8 +2151,13 @@ public class TimeBasedAccessInterceptor extends HandlerInterceptorAdapter {
|
|||
<classname>ViewResolvers</classname>. The first
|
||||
<classname>View</classname> in the list that has a compatible
|
||||
<literal>Content-Type</literal> returns the representation to the
|
||||
client. The <literal>Accept</literal> header may include wildcards, for
|
||||
example text/*, in which case a <classname>View</classname> whose
|
||||
client. If a compatible view cannot be supplied by the
|
||||
<classname>ViewResolver</classname> chain, then the list of views specified
|
||||
through the <literal>DefaultViews</literal> property will be consulted. This
|
||||
latter option is appropriate for singleton <classname>Views</classname> that
|
||||
can render an appropriate representation of the current resource regardless
|
||||
of the logical view name. The <literal>Accept</literal> header may include
|
||||
wildcards, for example text/*, in which case a <classname>View</classname> whose
|
||||
Context-Type was text/xml is a compatible match.</para>
|
||||
|
||||
<para>To support the resolution of a view based on a file extension,
|
||||
|
@ -2170,6 +2175,7 @@ public class TimeBasedAccessInterceptor extends HandlerInterceptorAdapter {
|
|||
<map>
|
||||
<entry key="atom" value="application/atom+xml"/>
|
||||
<entry key="html" value="text/html"/>
|
||||
<entry key="json" value="application/json"/>
|
||||
</map>
|
||||
</property>
|
||||
<property name="viewResolvers">
|
||||
|
@ -2181,6 +2187,11 @@ public class TimeBasedAccessInterceptor extends HandlerInterceptorAdapter {
|
|||
</bean>
|
||||
</list>
|
||||
</property>
|
||||
<property name="defaultViews">
|
||||
<list>
|
||||
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
|
@ -2206,10 +2217,12 @@ public class TimeBasedAccessInterceptor extends HandlerInterceptorAdapter {
|
|||
matches the <literal>application/atom+xml</literal> media type. This view is provided by
|
||||
the <classname>BeanNameViewResolver</classname> that maps to the
|
||||
<classname>SampleContentAtomView</classname> if the view name returned
|
||||
is <classname>content</classname>. Alternatively, client requests can be
|
||||
made without a file extension but with the <literal>Accept</literal> header set to the
|
||||
preferred media-type, and the same resolution of request to views would
|
||||
occur.<!--Can you reword preceding sentence? I don't follow it.--></para>
|
||||
is <classname>content</classname>. If the request is made with the file extension
|
||||
<literal>.json</literal>, the <classname>MappingJacksonJsonView</classname> instance from
|
||||
the <literal>DefaultViews</literal> list will be selected regardless of the view name.
|
||||
Alternatively, client requests can be made without a file extension but with the
|
||||
<literal>Accept</literal> header set to the preferred media-type, and the same resolution
|
||||
of request to views would occur.<!--Can you reword preceding sentence? I don't follow it.--></para>
|
||||
|
||||
<note>
|
||||
<para>If <classname>ContentNegotiatingViewResolver</classname>'s list
|
||||
|
|
|
@ -1414,7 +1414,8 @@ if (HttpStatus.SC_CREATED == post.getStatusCode()) {
|
|||
<classname>SourceHttpMessageConverter</classname>. You can override
|
||||
these defaults using the <methodname>messageConverters</methodname> bean
|
||||
property as would be required if using the
|
||||
<classname>MarshallingHttpMessageConverter</classname>.</para>
|
||||
<classname>MarshallingHttpMessageConverter</classname> or
|
||||
<classname>MappingJacksonHttpMessageConverter</classname>.</para>
|
||||
|
||||
<para>Each method takes URI template arguments in two forms, either as a
|
||||
<literal>String</literal> variable length argument or a
|
||||
|
@ -1577,6 +1578,20 @@ URI location = template.postForLocation(uri, booking, "1");
|
|||
this converter supports (<literal>text/xml</literal>) and
|
||||
(<literal>application/xml</literal>).</para>
|
||||
</section>
|
||||
|
||||
<section id="rest-mapping-json-converter">
|
||||
<title>MappingJacksonHttpMessageConverter</title>
|
||||
|
||||
<para>An <interfacename>HttpMessageConverter</interfacename>
|
||||
implementation that can read and write JSON using Jackson's
|
||||
<interfacename>ObjectMapper</interfacename>. JSON mapping can be
|
||||
customized as needed through the use of Jackson's provided annotations. When
|
||||
further control is needed, a custom
|
||||
<interfacename>ObjectMapper</interfacename> can be injected through
|
||||
the <literal>ObjectMapper</literal> property for cases where custom
|
||||
JSON serializers/deserializers need to be provided for specific types.
|
||||
By default this converter supports (<literal>application/json</literal>).</para>
|
||||
</section>
|
||||
|
||||
<section id="rest-source-converter">
|
||||
<title>SourceHttpMessageConverter</title>
|
||||
|
|
|
@ -2589,5 +2589,24 @@ simpleReport.reportDataKey=myBeanData</programlisting>
|
|||
chapter <link linkend="oxm">Marshalling XML using O/X
|
||||
Mappers</link>.</para>
|
||||
</section>
|
||||
|
||||
<section id="view-json-mapping">
|
||||
<title>JSON Mapping View</title>
|
||||
|
||||
<para>The <classname>MappingJacksonJsonView</classname> uses the Jackson
|
||||
library's <classname>ObjectMapper</classname> to render the response content
|
||||
as JSON. By default, the entire contents of the model map (with the exception
|
||||
of framework-specific classes) will be encoded as JSON. For cases where the
|
||||
contents of the map need to be filtered, users may specify a specific set of
|
||||
model attributes to encode via the <literal>RenderedAttributes</literal>
|
||||
property.</para>
|
||||
|
||||
<para>JSON mapping can be customized as needed through the use of Jackson's provided
|
||||
annotations. When further control is needed, a custom
|
||||
<interfacename>ObjectMapper</interfacename> can be injected through the
|
||||
<literal>ObjectMapper</literal> property for cases where custom JSON
|
||||
serializers/deserializers need to be provided for specific types.</para>
|
||||
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
|
|
Loading…
Reference in New Issue