Advertisement
MadMax1028

CommaBigDecimalAdapter

Sep 1st, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. public class CommaBigDecimalAdapter extends XmlAdapter<String, BigDecimal> {
  2.     private final DecimalFormat format;
  3.    
  4.     public CommaBigDecimalAdapter() {
  5.         DecimalFormatSymbols symbols = new DecimalFormatSymbols();
  6.         symbols.setDecimalSeparator(',');
  7.        
  8.         format = new DecimalFormat();
  9.         format.setDecimalFormatSymbols(symbols);
  10.         format.setParseBigDecimal(true);
  11.         format.setGroupingUsed(false);
  12.         format.setMaximumFractionDigits(Integer.MAX_VALUE);
  13.     }
  14.    
  15.     @Override
  16.     public BigDecimal unmarshal(String v) throws ParseException {
  17.         return (BigDecimal) format.parse(v);
  18.     }
  19.    
  20.     @Override
  21.     public String marshal(BigDecimal v) {
  22.         return format.format(v);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement