Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@RequestBody unable to bind to XStream POJO.

 
Shriram Gopalakrishnan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you registered the HttpMessageConverter for XStream to your ContextNegotiatingViewResolver? You might also need to register a marshaller and unmarshaller.

Mark
 
Shriram Gopalakrishnan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark, this is how i have configured my marshaller. Is there anything missing thats needs to be added?

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic