Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom message converters registered with AnnotationMethodHandlerAdapter are not used, only the default ones are used. [SPR-7895] #12551

Closed
spring-projects-issues opened this issue Jan 18, 2011 · 5 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: invalid An issue that we don't feel is valid

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 18, 2011

Jack Woods opened SPR-7895 and commented

Custom message converters registered with AnnotationMethodHandlerAdapter are not used, only the default ones registered with <mvc:annotation-driven /> are used. I found that the setMessageConverters() method of AnnotationMethodHandlerAdapter class is called two times, one for the default and another one for the bean defined in the spring xml file. The one defined in the spring xml file is never used when doing actual marshalling and unmarshalling.

For example the following jibx message converter is not used:

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<util:list id="beanList">
<ref bean="marshallingHttpMessageConverter" />
</util:list>
</property>
</bean>
<bean id="marshallingHttpMessageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<constructor-arg ref="jixbUserMarshaller" />
<property name="supportedMediaTypes" value="text/xml" />
</bean>

<oxm:jibx-marshaller id="jixbUserMarshaller" target-class="com.company.restpoc.model.User" />

In my opinion the jibx support in Spring OXM is rather poor. We need to define a separate converter for each target-class. We don't need to do that kind of thing when using Jersey with Jibx. We just need two @Provider classes that implement MessageBodyReader and MessageBodyWriter. I have attached JIBXBodyReader and JIBXBodyWriter for your reference.


Affects: 3.0.5

Reference URL: http://forum.springframework.org/showthread.php?t=100244

Attachments:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 19, 2011

Rossen Stoyanchev commented

The custom message converters are ignored because the AnnotationMethodHandlerAdapter explicitly defined in the configuration is in addition to the one created by the mvc:annotation-driven/ element.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 19, 2011

Jack Woods commented

That means we can only use the default message converts created by mvc:annotation-driven/ with @ResponseBody ? If that is true then this issue can be classified as an enhancement instead of a bug. Either add the jaxb message converter as a default converter of make it possible for addtional message converters to be added to the default convert list. Also it would be good to mention this somewhere in the documentation (apologies if it is already mentioned).

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 19, 2011

Jack Woods commented

I saw your comment in the forum. As you said this issue has already been raised by other people (#11751, #12161, #11851). Feel free to delete this issue.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 18, 2011

Mcihal Wroblewski commented

I had problem with change alwaysUseFullPath for AnnotationMethodHandlerAdapter. Is was loaded only with four default messageConverters.

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:order="3" p:alwaysUseFullPath="true"/>

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" p:alwaysUseFullPath="true" p:order="3">
 	<property name="messageConverters">
        <list>
            <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
            <ref bean="stringHpptConverter"/>
            <bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
        </list>
    </property>
	<!-- 
		org.springframework.http.converter.ByteArrayHttpMessageConverter@150ff8e3
		org.springframework.http.converter.StringHttpMessageConverter@32f3fb36
		org.springframework.http.converter.ResourceHttpMessageConverter@2471809b
		org.springframework.http.converter.xml.SourceHttpMessageConverter@3c5a5e89
		org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter@68f457aa
		org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter@1fcd3ed6
		org.springframework.http.converter.json.MappingJacksonHttpMessageConverter@5b87851a
	-->
</bean>

<bean id="stringHpptConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
	<property name="writeAcceptCharset" value="false"/>
</bean>	

It resolved my problem.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 21, 2011

Rossen Stoyanchev commented

Closing as invalid since defining both an mvc:annotation-driven element an AnnotationMethodHandlerAdapter results in duplicate configuration rather than a customization of the message converters. Note however that the ability to register custom message converters is available in Spring 3.1 M1 (see #12161).

@spring-projects-issues spring-projects-issues added type: bug A general bug status: invalid An issue that we don't feel is valid in: data Issues in data modules (jdbc, orm, oxm, tx) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug A general bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

2 participants