Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9274699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:24:50+00:00 2026-06-18T16:24:50+00:00

I am using spring 3.1, and my application is already set up to send

  • 0

I am using spring 3.1, and my application is already set up to send and receive data in json format. Now I need to provide one request API that should return the same data but in xml format.
Please help me with this stuff or tell what I am doing wrong. I tried JAXB, but instead of xml I receive “406 Not Acceptable”.

My requests API:

/** 
* Gets objects in json format
*/
@RequestMapping(value = "/objects/json", method = RequestMethod.GET)
@ResponseBody
public List<MyObjectTO> getAll() {
    List<MyObjectTO> objectsList = new ArrayList<MyObjectTO>();
    //forming objects
    return objectsList;
}
/** 
* Gets objects in xml format
*/
@RequestMapping(value = "/objects/xml", method = RequestMethod.GET,headers={"Accept=application/xml"})
@ResponseBody
public ResponseList getAll() {
    ResponseList objectsList = new ResponseList ();
    //the same formation
    return objectsList;
}

Context

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

    <context:annotation-config/>
    <context:component-scan base-package="com.kenshoo.urlbuilder"/>

    <mvc:annotation-driven/>
    <mvc:view-controller path="/mainpage" view-name="mainpage"/>
    <util:properties id="addProps" location="classpath:config/addProps.properties"/>
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="alwaysUseFullPath" value="true"/>
    </bean>

    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="alwaysUseFullPath" value="true"/>
    </bean>

    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="mediaTypes">
            <map>
                <entry key="html" value="text/html"/>
                <entry key="json" value="application/json"/>
                <entry key="pdf" value="application/pdf"/>
            </map>
        </property>
        <property name="viewResolvers">
            <list>
                <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                    <property name="cache" value="true"/>
                    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
                    <property name="prefix" value="/WEB-INF/jsp/"/>
                    <property name="suffix" value=".jsp"/>
                </bean>
            </list>
        </property>

        <property name="defaultViews">
            <list>
                <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>
            </list>
        </property>
    </bean>

    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
</beans>

My changes: Added message converters to AnnotationMethodHandlerAdapter and inserted JAXB marshaller. But after this got response “406 Not Acceptable”:

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="alwaysUseFullPath" value="true"/>
    <property name="messageConverters">
       <list>
            <ref bean="marshallingConverter" />
       </list>
   </property>
</bean>

<bean id="marshallingConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
     <property name="marshaller" ref="jaxbMarshaller" />
      <property name="unmarshaller" ref="jaxbMarshaller" />
      <property name="supportedMediaTypes" value="application/xml"/>
</bean>

<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
          <list>
            <value>com.ResponseList</value>
          </list>
    </property>
</bean>

I would appreciate any help, thanks.

UPDATE
ResponseList structure:

public class ResponseList {

    private List<FirstLevel> firstLevelObjects;

    public List<FirstLevel> getFirstLevelObjects() {
        return firstLevelObjects;
    }

    public void setFirstLevelObjects(List<FirstLevel> firstLevelObjects) {
        this.firstLevelObjects= firstLevelObjects;
    }

}

FirstLevel structure:

public class FirstLevel {
    List<SecondLevel> secondLevelObjects; 
    boolean isConditional;
    String beforeStart;
    ConditionType type;//enum object
    //...getters and setters
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:24:51+00:00Added an answer on June 18, 2026 at 4:24 pm

    I lost hope with Castor, so tried once more with JAXB. Changed post
    with details for JAXB. The same issues – I got Not Acceptable when
    trying to request xml. Can you help me?

    All you should need to do for JAXB is to add an @XmlRootElement annotation to your ResponseList class.

    import javax.xml.bind.annotation.XmlRootElement;
    
    @XmlRootElement
    public class ResponseList {
    
        private List<FirstLevel> firstLevelObjects;
    
        public List<FirstLevel> getFirstLevelObjects() {
            return firstLevelObjects;
        }
    
        public void setFirstLevelObjects(List<FirstLevel> firstLevelObjects) {
            this.firstLevelObjects= firstLevelObjects;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Spring's form tag library in a Spring MVC application that I am
I'm creating a web application using spring mvc. I have started to incorporate the
I'm doing a Web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate
I have this web application using Spring Web Flow framework. In my main page
We are developing a web application using Spring framework and Hibernate ORM. As far
I have a web application using spring annotations extensivley and I have my proguard
I'm doing a Web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate
I am working on an application using Spring 3 and Hibernate 3.5 with Java
I'd like to run my Spring application using STS, but I have no idea
I'm trying to run my web application using Spring, Hibernate and Apache Tiles. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.