Dmitry Katsubo opened SPR-13457 and commented
I think someone can benefit from the following improvement. I would like to configure JAXB marshallers based on bound classes like that:
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.xml.CompoundMarshallingHttpMessageConverter">
<constructor-arg>
<array>
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="marshallerProperties">
<map>
<entry key="com.sun.xml.bind.xmlHeaders" value="<?xml-stylesheet type='text/xsl' href='../xsl/statistics-job.xsl'?>" />
<entry key="#{T(javax.xml.bind.Marshaller).JAXB_FORMATTED_OUTPUT}" value="false" />
</map>
</property>
<property name="classesToBeBound">
<array>
<value>org.mycompany.statistics.model.JobStatistics</value>
</array>
</property>
</bean>
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="marshallerProperties">
<map>
<entry key="com.sun.xml.bind.xmlHeaders" value="<?xml-stylesheet type='text/xsl' href='../xsl/statistics-performance.xsl'?>" />
<entry key="#{T(javax.xml.bind.Marshaller).JAXB_FORMATTED_OUTPUT}" value="true" />
</map>
</property>
<property name="classesToBeBound">
<array>
<value>org.mycompany.statistics.model.PerformanceStatistics</value>
</array>
</property>
</bean>
</array>
</constructor-arg>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
The best is that MarshallingHttpMessageConverter
supports multiple marshallers/unmarshallers, but it could be a separate class (see [^CompoundMarshallingHttpMessageConverter.java]) that supports that.
P.S. I have expressed this idea in #15096, but decided to formulate it as a separate issue.
Affects: 4.1.7
Attachments: - CompoundMarshallingHttpMessageConverter.java (1.86 kB)
Issue Links: - #16357 Jaxb2Marshaller support unmarshalling by type