package com.megatim.fdxconsultation.service.impl.sockets.encoders; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.megatim.fdxcommons.model.dataproduction.CommonDataProduction; import javax.websocket.EncodeException; import javax.websocket.Encoder; import javax.websocket.EndpointConfig; /** * * @author lenovo */ public class DataProductionEncoder implements Encoder.Text { private final ObjectMapper objectMapper = new ObjectMapper(); @Override public String encode(CommonDataProduction dataProduction) throws EncodeException { try { return objectMapper.writeValueAsString(dataProduction); } catch (JsonProcessingException e) { throw new EncodeException(dataProduction, "Unable to encode message", e); } } @Override public void init(EndpointConfig endpointConfig) { } @Override public void destroy() { } }