@Test public void encode() throws NoSuchFieldException, IllegalAccessException, IOException, SQLException { java.lang.reflect.Field reflectField = parser.getClass().getDeclaredField("MAPPER"); reflectField.setAccessible(true); ObjectMapper mapper = (ObjectMapper)reflectField.get(null); Field field = new Field("bigint_type", JDBCType.BIGINT.getVendorTypeNumber(), new Long(9223372036854775807L)); byte[] bytes = mapper.writeValueAsBytes(field); Field sameField = mapper.readValue(bytes, Field.class); Assertions.assertTrue(DataCompareUtils.isFieldEquals(field, sameField).getResult()); field = new Field("decimal_type", JDBCType.DECIMAL.getVendorTypeNumber(), new BigDecimal("55555555555555555555.55555555555555555555")); bytes = mapper.writeValueAsBytes(field); sameField = mapper.readValue(bytes, Field.class); Assertions.assertTrue(DataCompareUtils.isFieldEquals(field, sameField).getResult()); field = new Field("double_type", JDBCType.DOUBLE.getVendorTypeNumber(), 999999.999999999); bytes = mapper.writeValueAsBytes(field); sameField = mapper.readValue(bytes, Field.class); Assertions.assertTrue(DataCompareUtils.isFieldEquals(field, sameField).getResult()); field = new Field("timestamp_type", JDBCType.TIMESTAMP.getVendorTypeNumber(), Timestamp.valueOf("2019-08-10 10:49:26.926554")); bytes = mapper.writeValueAsBytes(field); sameField = mapper.readValue(bytes, Field.class); Assertions.assertTrue(DataCompareUtils.isFieldEquals(field, sameField).getResult()); field = new Field("blob_type", JDBCType.BLOB.getVendorTypeNumber(), new SerialBlob("hello".getBytes())); bytes = mapper.writeValueAsBytes(field); sameField = mapper.readValue(bytes, Field.class); Assertions.assertTrue(DataCompareUtils.isFieldEquals(field, sameField).getResult()); field = new Field("clob_type", JDBCType.CLOB.getVendorTypeNumber(), new SerialClob("hello".toCharArray())); bytes = mapper.writeValueAsBytes(field); sameField = mapper.readValue(bytes, Field.class); Assertions.assertTrue(DataCompareUtils.isFieldEquals(field, sameField).getResult()); }
@Override public byte[] encode(BranchUndoLog branchUndoLog) { try { byte[] bytes = MAPPER.writeValueAsBytes(branchUndoLog); return bytes; } catch (JsonProcessingException e) { LOGGER.error("json encode exception, {}", e.getMessage(), e); throw new RuntimeException(e); } }
JacksonUndoLogParser implements UndoLogParser { @Override public byte[] encode(BranchUndoLog branchUndoLog) { try { byte[] bytes = MAPPER.writeValueAsBytes(branchUndoLog); return bytes; } catch (JsonProcessingException e) { LOGGER.error("json encode exception, {}", e.getMessage(), e); throw new RuntimeException(e); } } }
JacksonUndoLogParser implements UndoLogParser { @Override public byte[] encode(BranchUndoLog branchUndoLog) { try { byte[] bytes = MAPPER.writeValueAsBytes(branchUndoLog); return bytes; } catch (JsonProcessingException e) { LOGGER.error("json encode exception, {}", e.getMessage(), e); throw new RuntimeException(e); } }  }
JacksonUndoLogParser implements UndoLogParser { @Override public byte[] encode(BranchUndoLog branchUndoLog) { try { byte[] bytes = MAPPER.writeValueAsBytes(branchUndoLog); return bytes; } catch (JsonProcessingException e) { LOGGER.error("json encode exception, {}", e.getMessage(), e); throw new RuntimeException(e); } }  @Override String getName(); @Override byte[] getDefaultContent(); @Override byte[] encode(BranchUndoLog branchUndoLog); @Override BranchUndoLog decode(byte[] bytes); }
JacksonUndoLogParser implements UndoLogParser { @Override public byte[] encode(BranchUndoLog branchUndoLog) { try { byte[] bytes = MAPPER.writeValueAsBytes(branchUndoLog); return bytes; } catch (JsonProcessingException e) { LOGGER.error("json encode exception, {}", e.getMessage(), e); throw new RuntimeException(e); } }  @Override String getName(); @Override byte[] getDefaultContent(); @Override byte[] encode(BranchUndoLog branchUndoLog); @Override BranchUndoLog decode(byte[] bytes); static final String NAME; }