From cc5918dd50089991feaf7353f76b922ebbebe4fb Mon Sep 17 00:00:00 2001 From: Enrique Zamudio Date: Tue, 23 Apr 2013 11:22:21 -0500 Subject: [PATCH] Fix #10 - improve use of type parameters instead of suppressing warnings --- .../parse/AlphaNumericFieldParseInfo.java | 14 ++++----- .../solab/iso8583/parse/AlphaParseInfo.java | 15 +++++----- .../solab/iso8583/parse/AmountParseInfo.java | 14 +++++---- .../solab/iso8583/parse/BinaryParseInfo.java | 26 +++++++---------- .../com/solab/iso8583/parse/ConfigParser.java | 5 ++-- .../solab/iso8583/parse/Date10ParseInfo.java | 8 ++--- .../solab/iso8583/parse/Date4ParseInfo.java | 8 ++--- .../solab/iso8583/parse/DateExpParseInfo.java | 8 ++--- .../solab/iso8583/parse/FieldParseInfo.java | 8 ++--- .../solab/iso8583/parse/LlbinParseInfo.java | 27 +++++++---------- .../solab/iso8583/parse/LllbinParseInfo.java | 29 +++++++------------ .../solab/iso8583/parse/LllvarParseInfo.java | 16 +++++----- .../solab/iso8583/parse/LlvarParseInfo.java | 28 ++++++++---------- .../solab/iso8583/parse/NumericParseInfo.java | 5 ++-- .../solab/iso8583/parse/TimeParseInfo.java | 8 ++--- 15 files changed, 98 insertions(+), 121 deletions(-) diff --git a/src/main/java/com/solab/iso8583/parse/AlphaNumericFieldParseInfo.java b/src/main/java/com/solab/iso8583/parse/AlphaNumericFieldParseInfo.java index 8d115c3..e3148e2 100644 --- a/src/main/java/com/solab/iso8583/parse/AlphaNumericFieldParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/AlphaNumericFieldParseInfo.java @@ -35,8 +35,9 @@ public abstract class AlphaNumericFieldParseInfo extends FieldParseInfo { super(t, len); } - public IsoValue parse(final int field, final byte[] buf, final int pos, - final CustomField custom) + @Override + public IsoValue parse(final int field, final byte[] buf, final int pos, + final CustomField custom) throws ParseException, UnsupportedEncodingException { if (pos < 0) { throw new ParseException(String.format("Invalid ALPHA/NUM field %d position %d", @@ -53,12 +54,9 @@ public abstract class AlphaNumericFieldParseInfo extends FieldParseInfo { if (custom == null) { return new IsoValue(type, _v, length, null); } else { - @SuppressWarnings({"unchecked", "rawtypes"}) - IsoValue v = new IsoValue(type, custom.decodeField(_v), length, custom); - if (v.getValue() == null) { - return new IsoValue(type, _v, length, null); - } - return v; + T decoded = custom.decodeField(_v); + return decoded == null ? new IsoValue(type, _v, length, null) : + new IsoValue(type, decoded, length, custom); } } catch (StringIndexOutOfBoundsException ex) { throw new ParseException(String.format( diff --git a/src/main/java/com/solab/iso8583/parse/AlphaParseInfo.java b/src/main/java/com/solab/iso8583/parse/AlphaParseInfo.java index 12a5792..6ea5410 100644 --- a/src/main/java/com/solab/iso8583/parse/AlphaParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/AlphaParseInfo.java @@ -35,8 +35,9 @@ public class AlphaParseInfo extends AlphaNumericFieldParseInfo { super(IsoType.ALPHA, len); } - public IsoValue parseBinary(final int field, final byte[] buf, final int pos, - final CustomField custom) + @Override + public IsoValue parseBinary(final int field, final byte[] buf, final int pos, + final CustomField custom) throws ParseException, UnsupportedEncodingException { if (pos < 0) { throw new ParseException(String.format("Invalid bin ALPHA field %d position %d", @@ -50,12 +51,10 @@ public class AlphaParseInfo extends AlphaNumericFieldParseInfo { if (custom == null) { return new IsoValue(type, new String(buf, pos, length, getCharacterEncoding()), length, null); } else { - @SuppressWarnings({"unchecked", "rawtypes"}) - IsoValue v = new IsoValue(type, custom.decodeField(new String(buf, pos, length, getCharacterEncoding())), length, custom); - if (v.getValue() == null) { - return new IsoValue(type, new String(buf, pos, length, getCharacterEncoding()), length, null); - } - return v; + T decoded = custom.decodeField(new String(buf, pos, length, getCharacterEncoding())); + return decoded == null ? + new IsoValue(type, new String(buf, pos, length, getCharacterEncoding()), length, null) : + new IsoValue(type, decoded, length, custom); } } catch (IndexOutOfBoundsException ex) { throw new ParseException(String.format( diff --git a/src/main/java/com/solab/iso8583/parse/AmountParseInfo.java b/src/main/java/com/solab/iso8583/parse/AmountParseInfo.java index 4a45470..6e4c44b 100644 --- a/src/main/java/com/solab/iso8583/parse/AmountParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/AmountParseInfo.java @@ -37,8 +37,9 @@ public class AmountParseInfo extends FieldParseInfo { super(IsoType.AMOUNT, 12); } - public IsoValue parse(final int field, final byte[] buf, - final int pos, final CustomField custom) + @Override + public IsoValue parse(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException, UnsupportedEncodingException { if (pos < 0) { throw new ParseException(String.format("Invalid AMOUNT field %d position %d", @@ -50,7 +51,7 @@ public class AmountParseInfo extends FieldParseInfo { } String c = new String(buf, pos, 12, getCharacterEncoding()); try { - return new IsoValue(type, new BigDecimal(c).movePointLeft(2), null); + return new IsoValue(type, new BigDecimal(c).movePointLeft(2)); } catch (NumberFormatException ex) { throw new ParseException(String.format("Cannot read amount '%s' field %d pos %d", c, field, pos), pos); @@ -60,8 +61,9 @@ public class AmountParseInfo extends FieldParseInfo { } } - public IsoValue parseBinary(final int field, final byte[] buf, - final int pos, final CustomField custom) + @Override + public IsoValue parseBinary(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException { char[] digits = new char[13]; digits[10] = '.'; @@ -74,7 +76,7 @@ public class AmountParseInfo extends FieldParseInfo { } } try { - return new IsoValue(IsoType.AMOUNT, new BigDecimal(new String(digits)), null); + return new IsoValue(IsoType.AMOUNT, new BigDecimal(new String(digits))); } catch (NumberFormatException ex) { throw new ParseException(String.format("Cannot read amount '%s' field %d pos %d", new String(digits), field, pos), pos); diff --git a/src/main/java/com/solab/iso8583/parse/BinaryParseInfo.java b/src/main/java/com/solab/iso8583/parse/BinaryParseInfo.java index e02e15a..0def120 100644 --- a/src/main/java/com/solab/iso8583/parse/BinaryParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/BinaryParseInfo.java @@ -38,8 +38,8 @@ public class BinaryParseInfo extends FieldParseInfo { } @Override - public IsoValue parse(final int field, final byte[] buf, final int pos, - final CustomField custom) + public IsoValue parse(final int field, final byte[] buf, final int pos, + final CustomField custom) throws ParseException, UnsupportedEncodingException { if (pos < 0) { throw new ParseException(String.format("Invalid BINARY field %d position %d", @@ -54,18 +54,15 @@ public class BinaryParseInfo extends FieldParseInfo { if (custom == null) { return new IsoValue(type, binval, binval.length, null); } else { - @SuppressWarnings({"unchecked", "rawtypes"}) - IsoValue v = new IsoValue(type, custom.decodeField(new String(buf, pos, length*2, getCharacterEncoding())), length, custom); - if (v.getValue() == null) { - return new IsoValue(type, binval, binval.length, null); - } - return v; + T dec = custom.decodeField(new String(buf, pos, length*2, getCharacterEncoding())); + return dec == null ? new IsoValue(type, binval, binval.length, null) : + new IsoValue(type, dec, length, custom); } } @Override - public IsoValue parseBinary(final int field, final byte[] buf, final int pos, - final CustomField custom) throws ParseException { + public IsoValue parseBinary(final int field, final byte[] buf, final int pos, + final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid BINARY field %d position %d", field, pos), pos); @@ -80,12 +77,9 @@ public class BinaryParseInfo extends FieldParseInfo { if (custom == null) { return new IsoValue(type, _v, length, null); } else { - @SuppressWarnings({"unchecked", "rawtypes"}) - IsoValue v = new IsoValue(type, custom.decodeField(HexCodec.hexEncode(_v, 0, _v.length)), length, custom); - if (v.getValue() == null) { - return new IsoValue(type, _v, length, null); - } - return v; + T dec = custom.decodeField(HexCodec.hexEncode(_v, 0, _v.length)); + return dec == null ? new IsoValue(type, _v, length, null) : + new IsoValue(type, dec, length, custom); } } diff --git a/src/main/java/com/solab/iso8583/parse/ConfigParser.java b/src/main/java/com/solab/iso8583/parse/ConfigParser.java index f099555..3a91ecc 100644 --- a/src/main/java/com/solab/iso8583/parse/ConfigParser.java +++ b/src/main/java/com/solab/iso8583/parse/ConfigParser.java @@ -169,7 +169,8 @@ public class ConfigParser { throw new IOException("Invalid ISO8583 type for template: " + elem.getAttribute("type")); } NodeList fields = elem.getElementsByTagName("field"); - IsoMessage m = new IsoMessage(); + @SuppressWarnings("unchecked") + T m = (T)new IsoMessage(); m.setType(type); m.setCharacterEncoding(mfact.getCharacterEncoding()); for (int j = 0; j < fields.getLength(); j++) { @@ -184,7 +185,7 @@ public class ConfigParser { CustomField _cf = mfact.getCustomField(num); m.setValue(num, _cf == null ? v : _cf.decodeField(v), _cf, itype, length); } - mfact.addMessageTemplate((T)m); + mfact.addMessageTemplate(m); } //Read the parsing guides diff --git a/src/main/java/com/solab/iso8583/parse/Date10ParseInfo.java b/src/main/java/com/solab/iso8583/parse/Date10ParseInfo.java index 71b4c09..7118dc0 100644 --- a/src/main/java/com/solab/iso8583/parse/Date10ParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/Date10ParseInfo.java @@ -42,8 +42,8 @@ public class Date10ParseInfo extends FieldParseInfo { } @Override - public IsoValue parse(final int field, final byte[] buf, - final int pos, final CustomField custom) + public IsoValue parse(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid DATE10 field %d position %d", @@ -68,8 +68,8 @@ public class Date10ParseInfo extends FieldParseInfo { } @Override - public IsoValue parseBinary(final int field, final byte[] buf, - final int pos, final CustomField custom) + public IsoValue parseBinary(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid DATE10 field %d position %d", diff --git a/src/main/java/com/solab/iso8583/parse/Date4ParseInfo.java b/src/main/java/com/solab/iso8583/parse/Date4ParseInfo.java index b3e640c..3fa3c06 100644 --- a/src/main/java/com/solab/iso8583/parse/Date4ParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/Date4ParseInfo.java @@ -37,8 +37,8 @@ public class Date4ParseInfo extends FieldParseInfo { } @Override - public IsoValue parse(final int field, final byte[] buf, final int pos, - final CustomField custom) throws ParseException { + public IsoValue parse(final int field, final byte[] buf, final int pos, + final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid DATE4 field %d position %d", field, pos), pos); @@ -60,8 +60,8 @@ public class Date4ParseInfo extends FieldParseInfo { } @Override - public IsoValue parseBinary(final int field, final byte[] buf, final int pos, - final CustomField custom) throws ParseException { + public IsoValue parseBinary(final int field, final byte[] buf, final int pos, + final CustomField custom) throws ParseException { int[] tens = new int[2]; int start = 0; if (buf.length-pos < 2) { diff --git a/src/main/java/com/solab/iso8583/parse/DateExpParseInfo.java b/src/main/java/com/solab/iso8583/parse/DateExpParseInfo.java index 8d2f39f..8e6ef9a 100644 --- a/src/main/java/com/solab/iso8583/parse/DateExpParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/DateExpParseInfo.java @@ -37,8 +37,8 @@ public class DateExpParseInfo extends FieldParseInfo { } @Override - public IsoValue parse(final int field, final byte[] buf, - final int pos, final CustomField custom) + public IsoValue parse(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid DATE_EXP field %d position %d", @@ -61,8 +61,8 @@ public class DateExpParseInfo extends FieldParseInfo { } @Override - public IsoValue parseBinary(final int field, final byte[] buf, - final int pos, final CustomField custom) + public IsoValue parseBinary(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid DATE_EXP field %d position %d", diff --git a/src/main/java/com/solab/iso8583/parse/FieldParseInfo.java b/src/main/java/com/solab/iso8583/parse/FieldParseInfo.java index bc75d8d..3094c8d 100644 --- a/src/main/java/com/solab/iso8583/parse/FieldParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/FieldParseInfo.java @@ -70,8 +70,8 @@ public abstract class FieldParseInfo { * @param buf The full ISO message buffer. * @param pos The starting position for the field data. * @param custom A CustomField to decode the field. */ - public abstract IsoValue parse(final int field, byte[] buf, int pos, - CustomField custom) + public abstract IsoValue parse(final int field, byte[] buf, int pos, + CustomField custom) throws ParseException, UnsupportedEncodingException; /** Parses binary data from the buffer, creating and returning an IsoValue of the configured @@ -80,8 +80,8 @@ public abstract class FieldParseInfo { * @param buf The full ISO message buffer. * @param pos The starting position for the field data. * @param custom A CustomField to decode the field. */ - public abstract IsoValue parseBinary(final int field, byte[] buf, int pos, - CustomField custom) + public abstract IsoValue parseBinary(final int field, byte[] buf, int pos, + CustomField custom) throws ParseException, UnsupportedEncodingException; /** Returns a new FieldParseInfo instance that can parse the specified type. */ diff --git a/src/main/java/com/solab/iso8583/parse/LlbinParseInfo.java b/src/main/java/com/solab/iso8583/parse/LlbinParseInfo.java index 24c3a8c..b0d551e 100644 --- a/src/main/java/com/solab/iso8583/parse/LlbinParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/LlbinParseInfo.java @@ -37,8 +37,8 @@ public class LlbinParseInfo extends FieldParseInfo { } @Override - public IsoValue parse(final int field, final byte[] buf, - final int pos, final CustomField custom) + public IsoValue parse(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid LLBIN field %d position %d", @@ -62,13 +62,9 @@ public class LlbinParseInfo extends FieldParseInfo { return new IsoValue(type, binval, binval.length, null); } else { try { - @SuppressWarnings({"unchecked", "rawtypes"}) - IsoValue v = new IsoValue(type, custom.decodeField( - new String(buf, pos + 2, length)), binval.length, custom); - if (v.getValue() == null) { - return new IsoValue(type, binval, binval.length, null); - } - return v; + T dec = custom.decodeField(new String(buf, pos + 2, length)); + return dec == null ? new IsoValue(type, binval, binval.length, null) : + new IsoValue(type, dec, binval.length, custom); } catch (IndexOutOfBoundsException ex) { throw new ParseException(String.format( "Insufficient data for LLBIN field %d, pos %d (LEN states '%s')", @@ -78,8 +74,8 @@ public class LlbinParseInfo extends FieldParseInfo { } @Override - public IsoValue parseBinary(final int field, final byte[] buf, - final int pos, final CustomField custom) + public IsoValue parseBinary(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid bin LLBIN field %d position %d", @@ -101,12 +97,9 @@ public class LlbinParseInfo extends FieldParseInfo { if (custom == null) { return new IsoValue(type, _v, null); } else { - @SuppressWarnings({"unchecked", "rawtypes"}) - IsoValue v = new IsoValue(type, custom.decodeField(HexCodec.hexEncode(_v, 0, _v.length)), custom); - if (v.getValue() == null) { - return new IsoValue(type, _v, null); - } - return v; + T dec = custom.decodeField(HexCodec.hexEncode(_v, 0, _v.length)); + return dec == null ? new IsoValue(type, _v, null) : + new IsoValue(type, dec, custom); } } diff --git a/src/main/java/com/solab/iso8583/parse/LllbinParseInfo.java b/src/main/java/com/solab/iso8583/parse/LllbinParseInfo.java index 43816d6..5ee4f8c 100644 --- a/src/main/java/com/solab/iso8583/parse/LllbinParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/LllbinParseInfo.java @@ -37,8 +37,8 @@ public class LllbinParseInfo extends FieldParseInfo { } @Override - public IsoValue parse(final int field, final byte[] buf, - final int pos, final CustomField custom) + public IsoValue parse(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid LLLBIN field %d pos %d", @@ -64,14 +64,10 @@ public class LllbinParseInfo extends FieldParseInfo { return new IsoValue(type, binval, binval.length, null); } else { try { - @SuppressWarnings({"unchecked", "rawtypes"}) - IsoValue v = new IsoValue(type, custom.decodeField( - length == 0 ? "" : new String(buf, pos + 3, length)), length, custom); - if (v.getValue() == null) { - //problems decoding? return the string - return new IsoValue(type, binval, binval.length, null); - } - return v; + T dec = custom.decodeField( + length == 0 ? "" : new String(buf, pos + 3, length)); + return dec == null ? new IsoValue(type, binval, binval.length, null) : + new IsoValue(type, dec, length, custom); } catch (IndexOutOfBoundsException ex) { throw new ParseException(String.format( "Insufficient data for LLLBIN field %d, pos %d", field, pos), pos); @@ -80,8 +76,8 @@ public class LllbinParseInfo extends FieldParseInfo { } @Override - public IsoValue parseBinary(final int field, final byte[] buf, - final int pos, final CustomField custom) + public IsoValue parseBinary(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid bin LLLBIN field %d pos %d", @@ -104,12 +100,9 @@ public class LllbinParseInfo extends FieldParseInfo { if (custom == null) { return new IsoValue(type, _v, null); } else { - @SuppressWarnings({"unchecked", "rawtypes"}) - IsoValue v = new IsoValue(type, custom.decodeField(HexCodec.hexEncode(_v, 0, _v.length)), custom); - if (v.getValue() == null) { - return new IsoValue(type, _v, null); - } - return v; + T dec = custom.decodeField(HexCodec.hexEncode(_v, 0, _v.length)); + return dec == null ? new IsoValue(type, _v, null) : + new IsoValue(type, dec, custom); } } diff --git a/src/main/java/com/solab/iso8583/parse/LllvarParseInfo.java b/src/main/java/com/solab/iso8583/parse/LllvarParseInfo.java index bb5f99c..9b472d2 100644 --- a/src/main/java/com/solab/iso8583/parse/LllvarParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/LllvarParseInfo.java @@ -36,8 +36,8 @@ public class LllvarParseInfo extends FieldParseInfo { super(IsoType.LLLVAR, 0); } - public IsoValue parse(final int field, final byte[] buf, - final int pos, final CustomField custom) + public IsoValue parse(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException, UnsupportedEncodingException { if (pos < 0) { throw new ParseException(String.format("Invalid LLLVAR field %d pos %d", @@ -74,14 +74,15 @@ public class LllvarParseInfo extends FieldParseInfo { if (custom == null) { return new IsoValue(type, _v, length, null); } else { - Object decoded = custom.decodeField(_v); + T decoded = custom.decodeField(_v); //If decode fails, return string; otherwise use the decoded object and its codec - return new IsoValue(type, decoded == null ? _v : decoded, length, decoded == null ? null : custom); + return decoded == null ? new IsoValue(type, _v, length, null) : + new IsoValue(type, decoded, length, custom); } } - public IsoValue parseBinary(final int field, final byte[] buf, - final int pos, final CustomField custom) + public IsoValue parseBinary(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException, UnsupportedEncodingException { if (pos < 0) { throw new ParseException(String.format("Invalid bin LLLVAR field %d pos %d", field, pos), pos); @@ -100,8 +101,7 @@ public class LllvarParseInfo extends FieldParseInfo { if (custom == null) { return new IsoValue(type, new String(buf, pos + 2, length, getCharacterEncoding()), null); } else { - @SuppressWarnings({"unchecked", "rawtypes"}) - IsoValue v = new IsoValue(type, custom.decodeField(new String(buf, pos + 2, length, getCharacterEncoding())), custom); + IsoValue v = new IsoValue(type, custom.decodeField(new String(buf, pos + 2, length, getCharacterEncoding())), custom); if (v.getValue() == null) { return new IsoValue(type, new String(buf, pos + 2, length, getCharacterEncoding()), null); } diff --git a/src/main/java/com/solab/iso8583/parse/LlvarParseInfo.java b/src/main/java/com/solab/iso8583/parse/LlvarParseInfo.java index 10b376b..8521508 100644 --- a/src/main/java/com/solab/iso8583/parse/LlvarParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/LlvarParseInfo.java @@ -35,8 +35,9 @@ public class LlvarParseInfo extends FieldParseInfo { super(IsoType.LLVAR, 0); } - public IsoValue parse(final int field, final byte[] buf, - final int pos, final CustomField custom) + @Override + public IsoValue parse(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException, UnsupportedEncodingException { if (pos < 0) { throw new ParseException(String.format("Invalid LLVAR field %d %d", field, pos), pos); @@ -67,17 +68,15 @@ public class LlvarParseInfo extends FieldParseInfo { if (custom == null) { return new IsoValue(type, _v, length, null); } else { - @SuppressWarnings({"unchecked", "rawtypes"}) - IsoValue v = new IsoValue(type, custom.decodeField(_v), length, custom); - if (v.getValue() == null) { - return new IsoValue(type, _v, length, null); - } - return v; + T dec = custom.decodeField(_v); + return dec == null ? new IsoValue(type, _v, length, null) : + new IsoValue(type, dec, length, custom); } } - public IsoValue parseBinary(final int field, final byte[] buf, - final int pos, final CustomField custom) + @Override + public IsoValue parseBinary(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException, UnsupportedEncodingException { if (pos < 0) { throw new ParseException(String.format("Invalid bin LLVAR field %d pos %d", @@ -98,12 +97,9 @@ public class LlvarParseInfo extends FieldParseInfo { if (custom == null) { return new IsoValue(type, new String(buf, pos + 1, length, getCharacterEncoding()), null); } else { - @SuppressWarnings({"unchecked", "rawtypes"}) - IsoValue v = new IsoValue(type, custom.decodeField(new String(buf, pos + 1, length, getCharacterEncoding())), custom); - if (v.getValue() == null) { - return new IsoValue(type, new String(buf, pos + 1, length, getCharacterEncoding()), null); - } - return v; + T dec = custom.decodeField(new String(buf, pos + 1, length, getCharacterEncoding())); + return dec == null ? new IsoValue(type, new String(buf, pos + 1, length, getCharacterEncoding()), null) : + new IsoValue(type, dec, custom); } } diff --git a/src/main/java/com/solab/iso8583/parse/NumericParseInfo.java b/src/main/java/com/solab/iso8583/parse/NumericParseInfo.java index c9e4eaf..d0f8904 100644 --- a/src/main/java/com/solab/iso8583/parse/NumericParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/NumericParseInfo.java @@ -35,8 +35,9 @@ public class NumericParseInfo extends AlphaNumericFieldParseInfo { super(IsoType.NUMERIC, len); } - public IsoValue parseBinary(final int field, final byte[] buf, - final int pos, final CustomField custom) + @Override + public IsoValue parseBinary(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid bin NUMERIC field %d pos %d", diff --git a/src/main/java/com/solab/iso8583/parse/TimeParseInfo.java b/src/main/java/com/solab/iso8583/parse/TimeParseInfo.java index edd583d..acd4e22 100644 --- a/src/main/java/com/solab/iso8583/parse/TimeParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/TimeParseInfo.java @@ -38,8 +38,8 @@ public class TimeParseInfo extends FieldParseInfo { } @Override - public IsoValue parse(final int field, final byte[] buf, - final int pos, final CustomField custom) + public IsoValue parse(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid TIME field %d pos %d", @@ -56,8 +56,8 @@ public class TimeParseInfo extends FieldParseInfo { } @Override - public IsoValue parseBinary(final int field, final byte[] buf, - final int pos, final CustomField custom) + public IsoValue parseBinary(final int field, final byte[] buf, + final int pos, final CustomField custom) throws ParseException { if (pos < 0) { throw new ParseException(String.format("Invalid bin TIME field %d pos %d",