1

Does it has built-in support or I have to do java objects to xml converting by myself? An example would be very helpful. Thanks!

1
  • It would also be helpful to show us what you've got so far, so we can see what style of controller you're using. Commented Jan 20, 2011 at 19:48

1 Answer 1

2

Assuming that you're using Spring 3, then you can have it automatically marshall the response to XML:

@RequestMapping("/someurl")
public @ResponseBody SomeObject someMethod() {

 ...
 return instanceOfSomeObject;
}

Then in your context you would register an instance of HttpMessageConverter that supports XML, such as MarshallingHttpMessageConverter (with an appropriate Marshaller configured).

Sign up to request clarification or add additional context in comments.

3 Comments

Can you please elaborate this part by an example " register an instance of HttpMessageConverter that supports XML, such as MarshallingHttpMessageConverter (with an appropriate Marshaller configured)"?
@Bobo Spring has an interface, HttpMessageConverter, that allows objects to be automatically converted to other formats when requested over http. For XML, one instance of this is the MarshallingHttpMessageConverter. It requires an implementation of Marshaller to work, such as Castor. So, if you set-up Castor and a MarshallingHttpMessageConverter in your spring context, that should be enough that if someone asks for text/xml it'll return XML.
I dont think I set up anything for that but it works as long as there is proper JAXB annotation for the Java Bean.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.