Skip to content

Views: setModelKey, setRenderedAttributes should be consistent [SPR-7210] #11869

@spring-projects-issues

Description

@spring-projects-issues

Neale Upstone opened SPR-7210 and commented

The following is required to use ContentNegotiatingViewResolver for XML and JSON.

The two views are inconsistent in how they determine what should be rendered. This could be improved, at least by having them implement one interface and a consistent behaviour, but possibly also by allowing the key to result bean to be specified in the view resolver.

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="order" value="1" />
        <property name="mediaTypes">
            <map>
                <entry key="json" value="application/json" />
                <entry key="xml" value="application/xml" />
            </map>
        </property>
        <property name="defaultViews">
            <list>
                <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" >
                    <property name="renderedAttributes" value="result.key"/>
                </bean>
                <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
                    <property name="modelKey" value="result.key"/>
                    <property name="marshaller" ref="xstreamMarshaller"/>
                </bean>
            </list>
        </property>
        <property name="ignoreAcceptHeader" value="true" />
    </bean>

Affects: 3.0.2

Referenced from: commits 5797fe7

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions