@ResponseBody unable to return XML

I have a REST Webservice returning an int via @responseBody and I want this response to be in XML, and I don't know how to achieve that despite many tries.

My controller is as follow:

@RequestMapping(value = "/UserByAppli", method = RequestMethod.GET)
public List<Application> getNbUserByAppli()
    return this.DAO.getNbUserByAppli();

And my application Object:

public class Application
    private String name;

    private int nbUsers;

    public Application()


It always returns application/json, and when I specify the header "Accept=application/xml" I get a 406 response code with org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation in Spring logs.

An explanation or a search direction would be appreciated...


Make sure you have JAXB2 in your classpath and have registered the appropriate message converter and pass the Accept: application/xml header. Also, like M. Deinum suggested, for the marshalling to work, you also need to wrap the <Application /> elements in another element <Applications />.

Need Your Help

Java - get the current class name?

java class classname

All I am trying to do is to get the current class name, and java appends a useless non-sense $1 to the end of my class name. How can I get rid of it and only return the actual class name?

How to run local c++ unit tests using google test in Xcode 6.1.1

c++ xcode unit-testing googletest

I am new to google test and xcode. Please provide any help.