JBoss Netty与JSON

3

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

是否有现成的实现方法可供选择,还是我需要自己编写?

谢谢,

Gil

1个回答

4
据我所知,Go不提供内置的JSON编码/解码器,但这并不意味着您必须从基本的HTTP处理程序开始。
1)在服务器管道中使用HttpRequestDecoder、HttpResponseEncoder。
2)然后,为JSON编码和解码实现HttpContentDecoder、HttpContentEncoder抽象类,在此处您需要通过提供OneToOneEncoder/Decoder实现来实现newContentDecoder、newContentEncoder方法。
您可以使用Google Gson编写OneToOneEncoder/Decoder实现。
然后将HttpContentDecoder、HttpContentEncoder实现添加到管道中。
有关更多详细信息,请参阅HttpContentDecompressor、HttpContentCompressor源代码。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接