Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class XmlDecimalAdapter extends XmlAdapter< String, BigDecimal >
- {
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////
- @Override
- public String marshal( BigDecimal value ) throws Exception
- {
- final String stringRepresentation = value.toString();
- if( value.compareTo( BigDecimal.ZERO ) < 0 ){
- String result = "-00000000000000";
- return result.substring( 0, result.length() - stringRepresentation.length() + 1 ) + stringRepresentation.substring( 1 );
- }
- String result = "000000000000000";
- return result.substring( 0, result.length() - stringRepresentation.length() ) + stringRepresentation;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////
- @Override
- public BigDecimal unmarshal( String value ) throws Exception
- {
- if( value.equals( "000000000000000" ) ){
- return BigDecimal.ZERO;
- }
- if( value.startsWith( "-") ){
- return new BigDecimal( value.replaceFirst( "^-0*", "-" ) );
- }
- return new BigDecimal( value.replaceFirst( "^0*", "" ) );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement