package com.armundia.core.websocket.pojo;

import java.util.logging.Logger;

import javax.json.bind.Jsonb;
import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

import com.armundia.core.JsonbProvider;


public class MessageEncoder implements Encoder.Text<WebSocketEvent> {

	static final Logger log = Logger.getLogger(MessageEncoder.class.getName());

	@Override
	public String encode(WebSocketEvent message) throws EncodeException {
		JsonbProvider provider = new JsonbProvider();
		Jsonb jsonb = provider.getContext(WebSocketEvent.class);
		return jsonb.toJson(message);
	}

	@Override
	public void init(EndpointConfig ec) {
		log.info("MessageEncoder - init method called");
	}

	@Override
	public void destroy() {
		log.info("MessageEncoder - destroy method called");
	}

}