IntegerToBigInteger extends IntegerToInteger { @Override public byte[] from(Object value, int length, int decimals, boolean addPadding) { if(value == null && this.defaultValue == null) { return null; } BigInteger i = value != null ? (BigInteger)value : new BigInteger(this.defaultValue); if(i.signum() == -1) { throw new TypeConverterException("Number can not be negative"); } byte[] strBytes; BigInteger absValue = i.abs(); if(absValue.signum() == 0) { strBytes = new byte[decimals + 1]; Arrays.fill(strBytes, ("0".getBytes(this.charset))[0]); } else { strBytes = absValue.toString().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 validate(Class<?> type, int size, int decimals); @Override BigInteger 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(new BigInteger("12147483648"), 11, -1, true); assertArrayEquals("12147483648".getBytes(StandardCharsets.UTF_8), bytes); }
@Test public void testFromNullValue() throws Exception { config.setDefaultValue("0"); typeConverter.initialize(config); assertArrayEquals("00".getBytes(StandardCharsets.UTF_8), typeConverter.from(null, 2, -1, true)); }
@Test public void testFromOverflow() throws Exception { expectedEx.expect(TypeConverterException.class); expectedEx.expectMessage("Field to small for value"); byte[] bytes = typeConverter.from(new BigInteger("12147483648"), 4, -1, true); }