class InternalJsonCodec extends AbstractCodec {

    @Override
    public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
        if (message instanceof IMessage) {
            Map<String, Object> map = MessageUtil.convertToHashMap((IMessage)message);
            String json = objectMapper.writeValueAsString(map);

            long seq = sequence.getAndIncrement();

            IoBuffer buffer = IoBuffer.allocate(json.length() + HEADER_SIZE);
            buffer.putLong(json.length());
            buffer.putLong(seq);
            buffer.put(json.getBytes());

            out.write(buffer.flip());

            ((IMessage) message).getMetaData().setRawMessage(buffer.array());

            if (logger.isDebugEnabled()) {
                logger.debug("encode() sequnce {} as hex [{}]", seq, buffer.getHexDump());
            }
        } else {
            out.write(message);
        }
    }

    public  InternalJsonCodec();

}