StringToLocalDateTime extends StringToString { @Override public byte[] from(Object value, int length, int decimals, boolean addPadding) { if(value == null) { if(this.defaultValue != null) { value = LocalDateTime.parse(this.defaultValue, formatter); } else { return null; } } byte[] strBytes = ((LocalDateTime)value).format(this.formatter).getBytes(this.charset); if (strBytes.length > length) { throw new TypeConverterException("Field to small for value: " + length + " < " + strBytes.length); } if (addPadding) { strBytes = padBytes(strBytes, length); } return strBytes; }  @Override void initialize(TypeConverterConfig config); @Override void validate(Class<?> type, int size, int decimals); @Override Object to(byte[] bytes, int offset, int length, int decimals, boolean removePadding); @Override byte[] from(Object value, int length, int decimals, boolean addPadding);  }
@Test public void testFrom() throws Exception { byte[] bytes = typeConverter.from(LocalDateTime.parse("2015-08-04T10:11:30"), 16, -1, true); assertArrayEquals("0020150804101130".getBytes(StandardCharsets.UTF_8), bytes); }
@Test public void testFromOverflow() throws Exception { expectedEx.expect(TypeConverterException.class); expectedEx.expectMessage("Field to small for value"); byte[] bytes = typeConverter.from(LocalDateTime.parse("2015-08-04T10:11:30"), 4, -1, true); }