File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes @RequestBody unable to bind to XStream POJO. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "@RequestBody unable to bind to XStream POJO." Watch "@RequestBody unable to bind to XStream POJO." New topic
Author

@RequestBody unable to bind to XStream POJO.

Shriram Gopalakrishnan
Ranch Hand

Joined: Feb 20, 2007
Posts: 44
Trying to post an xml data to spring rest api as given below:

@RequestMapping(value = "/views/store",method=RequestMethod.POST)
@XmlMimeType(value="application/xml")
public View addStore(@RequestBody StoreVO store){
System.out.println(store.getName());
}

StoreVO
@XStreamAlias("store")
public class StoreVO{
}

Request body is unable to bind it to value object, but its able to bind it to String.

Any quick help is appreciated.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Have you registered the HttpMessageConverter for XStream to your ContextNegotiatingViewResolver? You might also need to register a marshaller and unmarshaller.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Shriram Gopalakrishnan
Ranch Hand

Joined: Feb 20, 2007
Posts: 44
Thanks Mark, this is how i have configured my marshaller. Is there anything missing thats needs to be added?

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

There is a Code button above to keep your code indented. Posting without it makes it difficult to read.

Where is your configuration for your ContentNegotiatingViewResolver?

Thanks

Mark
Shriram Gopalakrishnan
Ranch Hand

Joined: Feb 20, 2007
Posts: 44
Sorry Mark, I had pasted the code in hurry but have corrected it now. So to answer your question I have not used ContentNegotiatingViewResolver since with above configuration i was able to receive XML output for an spring rest api but faced issues while trying to post xml data. In other words can you let me know the lines to inject in above config related to ContentNegotiatingViewResolver to resolve the issue

Thanks!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Shriram Gopalakrishnan wrote:Sorry Mark, I had pasted the code in hurry but have corrected it now. So to answer your question I have not used ContentNegotiatingViewResolver since with above configuration i was able to receive XML output for an spring rest api but faced issues while trying to post xml data. In other words can you let me know the lines to inject in above config related to ContentNegotiatingViewResolver to resolve the issue

Thanks!


Unfortunately, I can only point you to the Spring Framework documentation. There is a whole section on the ContentNegotiatingViewResolver.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: @RequestBody unable to bind to XStream POJO.