【统计】请问大家现在是Jackson1.x的多还是Jackson2.x的多?
刚刚研究了一下Jackson1.9.11版本的,结果发现Jackson都已经出来2.x的版本了,搜索网上很多教程都还是1.x的,请问大家现在使用的什么版本,使用2.x的童鞋比1.x有那些好处?
2.x的版本能支持springmvc ajax文件上传@responseBody 返回中的contentType=“text/html”吗(之前1.X)的版本ajax文件上传返回的json IE浏览器不认“application/json”,只好手动转化json之后加入contentType="text/html"才行。
自己坐沙发,坐等回答
第二问题是可以的,可以contentType="text/html"。
另外contentType不属于jackson范畴,contentType是响应头里面的一个参数,属于http里面的.
加一个mvc拦截器,如果是IE8及以下,生成视图或数据前,设置contentType = text/plain;charset=UTF-8
或者,Controller 直接返回 json字符串,springmvc 使用 StringHttpMessageConverter 处理
<bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg index="0"> <bean class="java.nio.charset.Charset" factory-method="forName"> <constructor-arg value="UTF-8" /> </bean> </constructor-arg> <property name="supportedMediaTypes"> <list> <value>text/plain;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> <value>application/xml;charset=UTF-8</value> <value>application/javascript;charset=UTF-8</value> <value>text/javascript;charset=UTF-8</value> <value>application/x-javascript;charset=UTF-8</value> </list> </property> <property name="writeAcceptCharset" value="false"/> </bean>
替换 RequestMappingHandlerAdapter 中的 stringHttpMessageConverter