1

I am using the following libraries:

  • spring-security-oauth2-2.0.9
  • spring-4.2.1
  • Gson - 2.2.4

and configured GsonHttpMessageConverter in applicationContext.xml:

<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>

Added :

  <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> 

By default spring-oauth2 uses jackson-converter to serialize/deserialize json. With including jackson libraries, I am not able to get the oauth token from spring TokenEndPoint service. When I comment the message-converters tag, I am able to get oauth token. Please let me know how I can use GsonHttpMessageConverter to get the oauth token, or is there any other way to obtain oauth token.

When debugged the GsonHttpMessageConverter code, it throws HttpMessageNotWritableException, please help. It seems that OAuth2AccessToken.java has expiration attribute which is java.util.Date type, can this be a problem with the configured converter. This converter we need for POST-ing json dates in that format. please help

Thanks in advance.

4

1 回答 1

1

我的 Http 请求对象包含一个 RECURSIVE 字段。Gson 转换器在 spring 中配置时自动将带有 RECURSIVE 字段对象的 HTTP 请求转换为它们的 db 对象,但是当它关​​闭时,它会抛出异常“不支持的媒体类型”。OAuth2Token 使用 Jackson 序列化器/反序列化器,因此当配置 Gson 转换器时,Spring 会抛出 HttpMessageNotWritableException。

谢谢

于 2016-03-11T12:21:22.787 回答