1

I'm using org.beanio to parse fixed-length records.

Unfortunately, there are price values where the integer and fractional part of the price is distributed to different locations.

Question: is it possible to define two @Fields to one single value, and extract different parts of the BigDecimal via format?

@Field(at = 20, length = 6, format = ...<the integer part>)
@Field(at = 100, length = 2, format = ...<the fractional part>) 
private BigDecimal price;
membersound
  • 81,582
  • 193
  • 585
  • 1,120

1 Answers1

1

I don't think it is possible , but you can simply map to 2 other fields and calculate the value ,

@Field(at = 20, length = 6)
private Integer priceWholeAmt;

@Field(at = 100, length = 2) 
private Integer priceChange;

public BigDecimal getPrice(){
   return new BigDecimal(priceWholeAmt).add(new BigDecimal(priceChange/100));
}
Sagar
  • 818
  • 1
  • 6
  • 13