java - ModelAttribute not mapping application/x-www-form-urlencoded -


i have simplistic controller configured thus:

@requestmapping(value = "user/savearticle", method = requestmethod.post) public @responsebody object savearticle(@modelattribute("article")rawarticle rawarticle); 

using snippets of code taken here, made test case controller looks this:

mvcresult resultactions =          mockmvc.perform(mockmvcrequestbuilders.post("/user/savearticle")          .contenttype(mediatype.application_form_urlencoded)          .content(convertobjecttoforumurlencodedbytes(rawarticle)))          .andreturn(); 

and print out result. in case, modelattribute "rawarticle" keeps ending null when enters controller's implementation, when use this:

mvcresult resultactions = mockmvc.perform(         mockmvcrequestbuilders.post("/user/savearticle")         .param("title", rawarticle.gettitle())         .param("tags", rawarticle.gettags())         .param("body", rawarticle.getbody())         .param("author", rawarticle.getauthor())).andreturn(); 

the mapping works charm. want though first test processed correctly seems wrong it's not being mapped thought should be, controller being used program on network using apache http (which somehow automatically passes urlencoded form).

do guys have idea could've made error? wouldn't mind posting snippets of context configuration if think need evaluate problem (or pom matter, telling me libraries may have missed should enough)

update: made mistake of inserting pojo session in test number 1, removed here. question stands same.

the content content body of request, using content type expects encoded in url not in content body. spring data binding based on request parameters if want use content body have use @requestbody instead of @modelattribute.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -