【问题标题】:JBoss Netty with JSON带有 JSON 的 JBoss Netty
【发布时间】:2012-01-04 15:36:55
【问题描述】:

我希望我的 Ajax 代码通过 Netty 连接服务器。为此,我需要在服务器端 Netty 处理程序中使用 JSON 解码器和编码器。

是否有任何开箱即用的实现,或者我应该自己编写?

谢谢,

吉尔

【问题讨论】:

    标签: json netty


    【解决方案1】:

    据我所知,没有内置的 JSON 解码器/编码器,但这并不意味着您必须从基本的 HTTP 处理程序开始。

    1)在服务器管道中有HttpRequestDecoder、HttpResponseEncoder。

    2) 然后为 JSON 解码和编码实现 HttpContentDecoder、HttpContentEncoder 抽象类,这里你必须通过为 JSON 提供 OneToOneEncoder/Decoder 实现来实现 newContentDecoder、newContentEncoder 方法。

    您可以使用 Google Gson 编写 OneToOneEncoder/Decoder 实现。

    然后在管道中添加 HttpContentDecoder、HttpContentEncoder 实现。

    更多细节,你可以看看 HttpContentDecompressor,HttpContentCompressor 源代码。

    【讨论】:

      猜你喜欢
      • 2017-08-04
      • 1970-01-01
      • 1970-01-01
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-24
      相关资源
      最近更新 更多