问题描述:

I am having a problem marshalling a RequestBody when the parent class has a namespace.

Class:

@XmlRootElement(name = "blah")

public class Test {

private String id;

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

}

XML:

<blah>

<id>23333</id>

</blah>

Code:

@RequestMapping( value = "/blah", method = RequestMethod.POST, consumes = { MediaType.TEXT_XML_VALUE }, produces = { MediaType.TEXT_XML_VALUE})

public String getBlah( @RequestBody Test request ) throws Exception

{

assert(null != request.getId());

return "blah";

}

This works fine. However, if I use @XmlRootElement(name = "blah", namespace="home") on the class, and <blah xmlns="home"> in the request, the Test class constructs, but it's ID value is never set.

I'm at a loss.

网友答案:

Before public void setId method add annotation @XmlElement

相关阅读:
Top