package com.gyee.frame.netty.websocket;

import com.alibaba.fastjson.JSONObject;


import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

/**
 *
 */
/**
 *@author:Wang Jiawen
 *
 *@description: socket 解码器
 *
 *@param:ServerEncoder为了防止在websocket向客户端发送sendObject方法的时候提示如下错误：javax.websocket.EncodeException: No encoder specified for object of class [class org.ywzn.po.Messagepojo]
 *@return:
 *
 *@createTime:2020/1/9
 *
 */
public class ServerEncoder implements Encoder.Text<Object>  {

    //代表websocket调用sendObject方法返回客户端的时候，必须返回的是DomainResponse对象
    @Override
    public String encode(Object object) {
        //将java对象转换为json字符串
        return JSONObject.toJSONString(object).toString();
    }
    @Override
    public void init(EndpointConfig endpointConfig) { }

    @Override
    public void destroy() { }
}