Announcement Announcement Module
Collapse
No announcement yet.
JAXBElement with REST: Could not find acceptable representation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JAXBElement with REST: Could not find acceptable representation

    Hi all,

    I try to return some JAXBElement in a REST controller.
    When i call my REST endpoint, i have an exception that say : "org.springframework.web.HttpMediaTypeNotAcceptable Exception: Could not find acceptable representation".

    The return type "JAXBElement<OrgListType>" and the "ObjectFactory" come from a tierce librairy.

    My REST endpoint is the following:
    Code:
    	@Autowired
    	private LoginService loginService;	
    
    	@RequestMapping(value = "/api/v1.0/login", method = RequestMethod.POST)
    	public @ResponseBody JAXBElement<OrgListType> login(HttpServletResponse response) throws Exception {
    		
    		ObjectFactory objectFactory = new ObjectFactory();
    		return objectFactory.createOrgList(loginService.login());
    	}
    My Spring REST configuration:
    Code:
    	<context:component-scan base-package="xxx.interaction.api" use-default-filters="false">
    		<context:include-filter expression="org.springframework.stereotype.Controller" type="annotation" />
    	</context:component-scan>
    
    	<mvc:annotation-driven />
    
    	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    		<property name="messageConverters">
    			<util:list id="beanList">
    				<ref bean="stringHttpMessageConverter" />
    				<ref bean="marshallingHttpMessageConverter" />
    			</util:list>
    		</property>
    	</bean>
    
    	<bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter" />
    
    	<bean id="marshallingHttpMessageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
    		<property name="marshaller" ref="jaxb2-marshaller" />
    		<property name="unmarshaller" ref="jaxb2-marshaller" />
    	</bean>
    
    	<oxm:jaxb2-marshaller id="jaxb2-marshaller" contextPath="com.vmware.vcloud.api.rest.schema"/>
    The package com.vmware.vcloud.api.rest.schema contain the OrgListType.

    I don't understand why Jaxb2 can't marshal the JAXBElement<OrgListType>.
Working...
X