2013-08-30 59 views
1

我正在使用@Responsebody字符串發送JSON。我的代碼 部分如下。(我很抱歉開放所有)如何通過Spring發送bson @response正文

@RequestMapping(value = "/getSomeList", method = RequestMethod.GET , 
      headers="Accept=application/json", produces = "text/plain;charset=UTF-8") 
    public @ResponseBody String getThumbList(
      @RequestParam("con_id") String con_id) throws Exception{ 
return json; 

} 

而實際上它發送JSON。但我的客戶請求Bson類型。如何在不編輯全局格式的情況下將Json更改爲Bson(我的json實際上只是字符串,我聽說spring不能響應bson,是嗎?)。

回答

1

您需要註冊可以轉換爲BSON的HttpMessageConverter

<mvc:annotation-driven> 
    <mvc:message-converters> 
      <bean class="MyBsonHttpMessageConverter"/> 
    </mvc:message-converters> 
</mvc:annotation-driven> 

不幸的是Spring沒有Bson Http消息轉換器,所以你必須實現你自己的。 (或者當我有更多的運氣時,谷歌一個)。