2017-01-28 4 views
0

私はそれを4時間ずっと試してみる、誰でもそれを動作させる方法を知っていますか?jacksonを作る方法Include.NON_NULLはspring4の@RestControllerで動作しますか?

私は私のservlet.xmlにこれらを記述してみました:

<mvc:annotation-driven> 
    <mvc:message-converters> 
     <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> 
      <property name="prefixJson" value="true"/> 
      <property name="supportedMediaTypes" value="application/json"/> 
      <property name="objectMapper"> 
       <bean class="com.fasterxml.jackson.databind.ObjectMapper"> 
        <property name="serializationInclusion" value="NON_NULL"/> 
       </bean> 
      </property> 
     </bean> 
    </mvc:message-converters> 
</mvc:annotation-driven> 

それがすべてでは動作しません。 私はspringのソースコードを読んで、それをEclipseでデバッグします。それが使用 messageConverterが

そして、私は、コードをトレースRequestResponseBodyMethodProcessor#RequestResponseBodyMethodProcessor(一覧> messageConverters、ContentNegotiationManager contentNegotiationManager、リストresponseBodyAdvice)によって構築されたオブジェクトであり、上記構築物は、メソッドが呼び出されるRequestMappingHandlerAdapter#1 getDefaultReturnValueHandlers()によって呼び出されカスタムの前に私のmessageConverterを設定してください。 上記の設定は機能しません。

ああ私の神様、どうすればいいのですか?

答えて

0

ジャクソン2.0以降、あなたのpojoで@JsonIncludeを使用することができます。

@JsonInclude(Include.NON_NULL) 
public class Pojo{ 

} 
関連する問題