java - Spring + Jackson Content type 'application/json;charset=UTF-8' not supported -
when posting jquery ajax, following error.
org.springframework.web.httpmediatypenotsupportedexception: content type 'application/json;charset=utf-8' not supported @ org.springframework.web.servlet.mvc.method.annotation.abstractmessageconvertermethodargumentresolver.readwithmessageconverters(abstractmessageconvertermethodargumentresolver.java:226) @ org.springframework.web.servlet.mvc.method.annotation.requestresponsebodymethodprocessor.readwithmessageconverters(requestresponsebodymethodprocessor.java:148) @ org.springframework.web.servlet.mvc.method.annotation.requestresponsebodymethodprocessor.resolveargument(requestresponsebodymethodprocessor.java:125) the interesting thing when debug
requestresponsebodymethodprocessor.java:148 and webrequest.getheader("content-type") value application/json. pretty normal.
but when comes last method of chain abstractmessageconvertermethodargumentresolver.java:226 content-type becomes application/json; charset=utf-8;
which throws exception. here code ;
controller
@requestmapping(value="/user/set-preference",method=requestmethod.post) @responsebody private boolean set_preference(@requestbody userpreference preference) { try{ userservice.save(preference); return true; }catch(exception ex){ return false; } } entity
@entity public class userpreference extends baseentity{ @manytoone(fetch=fetchtype.lazy) private user user; private string name; private string information; public user getuser() { return user; } public void setuser(user user) { this.user = user; } public string getname() { return name; } public void setname(string name) { this.name = name; } public string getinformation() { return information; } public void setinformation(string information) { this.information = information; } } spring mvc config
<mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.json.mappingjackson2httpmessageconverter"> <property name="objectmapper"> <bean class="com.test.hibernateawareobjectmapper" /> </property> </bean> </mvc:message-converters> </mvc:annotation-driven>
i had same problem , solved adding default constructor class. try it.
Comments
Post a Comment