Since we had to encode the Date and BigDecimal types so that they are correctly saved in the database, now we have to do the decoding:
Date date = getDate(dateLong);
BigDecimal price = getPrice(priceLong);
For this, we will create two methods. The first one will handle Date:
private Date getDate(long dateLong) {
return new Date(dateLong);
}
It will simply convert the milliseconds that are in the Long type format into the java.util.Date type.
Next is the conversion of the price to BigDecimal:
private BigDecimal getPrice(long priceLong) {
return new BigDecimal(priceLong).scaleByPowerOfTen(-4);
}
Again, it takes the Long type and converts it to BigDecimal. However, since we have scaled the value by 4 decimal points, now we have to do the reverse. It is achieved by calling this:
.scaleByPowerOfTen(-4);