我正在使用以下库:
并在applicationContext.xml中配置了GsonHttpMessageConverter:
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.GsonHttpMessageConverter">
<property name="gson" ref="gson"/>
<property name="supportedMediaTypes" value="application/json" />
<property name="prefixJson" value="false"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
补充:
<bean id="gsonFactoryBean" class="org.springframework.http.converter.json.GsonFactoryBean">
<property name="dateFormatPattern" value="yyyy'-'MM'-'dd"/>
<property name="disableHtmlEscaping" value="true"/>
<property name="prettyPrinting" value="true"/>
<!-- <property name="gson" ref="gson"/>-->
</bean>
<bean id="gsonBuilder" class="com.google.gson.GsonBuilder">
<property name="dateFormat" value="yyyy'-'MM'-'dd" />
</bean>
默认情况下,spring-oauth2使用jackson-converter序列化/反序列化json。包含jackson库,我无法从Spring TokenEndPoint服务获取oauth令牌。当我评论消息转换器标签时,我能够获得oauth令牌。请告诉我如何使用GsonHttpMessageConverter获取oauth令牌,或者是否有其他方法可以获取oauth令牌。
调试GsonHttpMessageConverter代码时,会抛出HttpMessageNotWritableException,请帮忙。看来OAuth2AccessToken.java的expiration属性是java.util.Date类型,这可能是配置转换器的问题。这个转换器我们需要以该格式发布json日期。请帮忙
提前致谢。
答案 0 :(得分:1)
我的Http请求对象包含RECURSIVE字段。在Spring中配置时,Gson转换器自动将具有RECURSIVE字段对象的HTTP请求转换为其db对象,但是当它关闭时,它会抛出异常&#34;不支持的媒体类型&#34;。 OAuth2Token使用Jackson序列化器/解串器,因此当配置Gson转换器时,Spring会抛出HttpMessageNotWritableException。
由于