package com.armundia.core.websocket.pojo;

import java.util.logging.Logger;

import javax.json.bind.Jsonb;
import javax.websocket.DecodeException;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;

import com.armundia.core.JsonbProvider;


public class MessageDecoder implements Decoder.Text<WebSocketEvent> {
	static final Logger log = Logger.getLogger(MessageDecoder.class.getName());

	@Override
	public WebSocketEvent decode(String jsonMessage) throws DecodeException {
		JsonbProvider provider = new JsonbProvider();
		Jsonb jsonb = provider.getContext(WebSocketEvent.class);
		return jsonb.fromJson(jsonMessage, WebSocketEvent.class);
	}

	@Override
	public boolean willDecode(String jsonMessage) {
		return true;
	}

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

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

}

