java - HttpMediaTypeNotAcceptableException when specifying applicaiton/xml in Accept header -
apologies, didn't see tag java-noob.
i working existing restful api in spring. tasked adding new api couple utility methods, each of return string. far good. working well.
i added simple wrapper return string object , i'm able build/deploy/test , response looks like
{ id: "12345" }
if specify accept header = application/xml
following exception:
org.springframework.web.httpmediatypenotacceptableexception: not find acceptable representation
other methods in package seem serialize in both xml , json fine. don't see custom serialization code being used in controller base , don't know handled (or if related serialization). can me figure out start looking?
here [simplified] controller:
@controller public class utilcontroller extends controllerbase { @xmlrootelement(name="util_response") public static class utilresponse extends apiresponsebase { private string id; @xmlelement(name="id") public string getid() { return id; } public void setid(string id) { this.id = id; } } @requestmapping(value = "/{pid}/util/output", method = requestmethod.get) @responsebody public utilresponse output(httpservletresponse httpresponse, @pathvariable("pid") int pid, @requestparam(value = "id", required=true) string id) throws exception { utilresponse utilresponse = new utilresponse(); utilresponse.setid(id); return utilresponse; } }
i tried updating @requestmapping
, added produces = "application/xml"
(yes, having no clue does), had 0 effect.
seriously, i'm new how java stuff "works" (.net dev trade) , love understand more. don't know jackson
is, don't see references in our project , else seems work please no responses "why don't use jackson?" have deadlines getting working takes precedence.
please no responses "why don't use jackson?
nobody that. jackson json
;)
produces = "application/xml" ..., had 0 effect
produces
restricts handler method provided types. produces="application\xml"
makes method unavailable requests expect json
, e.g. not change method's outcome.
your description of problem indicates spring not able finding way serialize utilresponse
xml
. cause jaxb2
not present on classpath. spring uses default create xml
.
Comments
Post a Comment