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

  • Home
  • SEARCH
  • 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 9042167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:25:08+00:00 2026-06-16T10:25:08+00:00

How can I take an xml that looks like: <request> <User> <name>name value</name> <age>13</age>

  • 0

How can I take an xml that looks like:

<request>
  <User>
    <name>name value</name>
    <age>13</age>
  </User>
</request>

And then I can deserialize this into a User object that has matching properties.

public class User {
  private String name;
  private Integer age;

  // getter and setters
}

Is there anything simple I can do or do I have to parse the xml manually for this?

I’m using spring mvc, and this is in a method where the xml will be posted.

  • 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-16T10:25:09+00:00Added an answer on June 16, 2026 at 10:25 am

    Your controller method should take an argument of type User, which is annotated with @RequestBody. Then you need to configure a MarshallingHttpMessageConverter with an appropriate marshaller/unmarshaller. An example, straight from the reference guide:

    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <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="castorMarshaller" />
      <property name="unmarshaller" ref="castorMarshaller" />
    </bean>
    
    <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller"/>
    

    Take a look at “Supported method argument types” and “Mapping the request body with the @RequestBody annotation” in the reference guide for more details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a field in my xml that looks like this (some examples): <ViolationCharged>VTL0180
I have a sample xml file that looks like this: <Books> <Category Genre=Fiction BookName=book_name
I have an xml file that looks like this... <fruits> <apple color=red/> <orange color=orange/>
My XML looks like this: <product id=1> <name>A thing</name> <description>This is what it's like</description>
I have an ant properties file that looks like this (although I can adjust
I have a list of name/value pairs that I would like to map into
xml2js to take my xml result so that i can access the values. I
Suppose my Tomcat webapps directory looks like this: webapps/ webapps/fooapp/ webapps/fooapp/WEB-INF/ webapps/fooapp/WEB-INF/web.xml webapps/fooapp/bardir/ When
Do you know how I could create an HTML element that looks like this:
I have a form that looks like this: <form method=post id=aodform> <label for=a>Animal:</label> <input

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.