### Question:
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); } } InternalJsonCodec(); @Override void encode(IoSession session, Object message, ProtocolEncoderOutput out); @Override void init(IServiceContext serviceContext, ICommonSettings settings, IMessageFactory msgFactory, IDictionaryStructure dictionary);  }### Answer:
@Test public void testEncode() throws Exception { IMessage msg = new MapMessage("namespace", "name"); msg.addField("MessageType", 123); msg.addField("Qty", 123.123); msg.addField("ClOrdID", ""); msg.addField("fieldDate", LocalDateTime.of(2010, Month.JANUARY, 1, 11, 22, 33, 444_555_666)); ProtocolDecoderOutput decoderOutput = Mockito.mock(ProtocolDecoderOutput.class); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { IMessage decoded = invocation.getArgument(0); Assert.assertEquals(msg.getFieldNames(), decoded.getFieldNames()); for (String column : decoded.getFieldNames()) { Assert.assertEquals(column, msg.<Object>getField(column), decoded.<Object>getField(column)); } return null; } }).when(decoderOutput).write(Mockito.anyObject()); ProtocolEncoderOutput encoderOutput = Mockito.mock(ProtocolEncoderOutput.class); Mockito.doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { codec.decode(session, invocation.getArgument(0), decoderOutput); return null; } } ).when(encoderOutput).write(Mockito.anyObject()); codec.encode(session, msg, encoderOutput); }