private void _parseSlowInt(int expType) throws IOException { String numStr = _textBuffer.contentsAsString(); try { int len = _intLength; char[] buf = _textBuffer.getTextBuffer(); int offset = _textBuffer.getTextOffset(); if (_numberNegative) { ++offset; } // Some long cases still... if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) { // Probably faster to construct a String, call parse, than to use BigInteger _numberLong = Long.parseLong(numStr); _numTypesValid = NR_LONG; } else { // nope, need the heavy guns... (rare case) _numberBigInt = new BigInteger(numStr); _numTypesValid = NR_BIGINT; } } catch (NumberFormatException nex) { // Can this ever occur? Due to overflow, maybe? _wrapError("Malformed numeric value '"+numStr+"'", nex); } }
/** * Convenience method for converting contents of the buffer * into a {@link BigDecimal}. */ public BigDecimal contentsAsDecimal() throws NumberFormatException { // Already got a pre-cut array? if (_resultArray != null) { return NumberInput.parseBigDecimal(_resultArray); } // Or a shared buffer? if ((_inputStart >= 0) && (_inputBuffer != null)) { return NumberInput.parseBigDecimal(_inputBuffer, _inputStart, _inputLen); } // Or if not, just a single buffer (the usual case) if ((_segmentSize == 0) && (_currentSegment != null)) { return NumberInput.parseBigDecimal(_currentSegment, 0, _currentSize); } // If not, let's just get it aggregated... return NumberInput.parseBigDecimal(contentsAsArray()); }
public void testIntParsing() throws Exception { char[] testChars = "123456789".toCharArray(); assertEquals(3, NumberInput.parseInt(testChars, 2, 1)); assertEquals(123, NumberInput.parseInt(testChars, 0, 3)); assertEquals(2345, NumberInput.parseInt(testChars, 1, 4)); assertEquals(9, NumberInput.parseInt(testChars, 8, 1)); assertEquals(456789, NumberInput.parseInt(testChars, 3, 6)); assertEquals(23456, NumberInput.parseInt(testChars, 1, 5)); assertEquals(123456789, NumberInput.parseInt(testChars, 0, 9)); testChars = "32".toCharArray(); assertEquals(32, NumberInput.parseInt(testChars, 0, 2)); testChars = "189".toCharArray(); assertEquals(189, NumberInput.parseInt(testChars, 0, 3)); testChars = "10".toCharArray(); assertEquals(10, NumberInput.parseInt(testChars, 0, 2)); assertEquals(0, NumberInput.parseInt(testChars, 1, 1)); }
public void testLongBoundsChecks() throws Exception { String minLong = String.valueOf(Long.MIN_VALUE).substring(1); String maxLong = String.valueOf(Long.MAX_VALUE); final String VALUE_491 = "1323372036854775807"; // is within range (JACKSON-491) final String OVERFLOW = "9999999999999999999"; // and this one is clearly out assertTrue(NumberInput.inLongRange(minLong, true)); assertTrue(NumberInput.inLongRange(maxLong, false)); assertTrue(NumberInput.inLongRange(VALUE_491, true)); assertTrue(NumberInput.inLongRange(VALUE_491, false)); assertFalse(NumberInput.inLongRange(OVERFLOW, false)); assertFalse(NumberInput.inLongRange(OVERFLOW, true)); char[] cbuf = minLong.toCharArray(); assertTrue(NumberInput.inLongRange(cbuf, 0, cbuf.length, true)); cbuf = maxLong.toCharArray(); assertTrue(NumberInput.inLongRange(cbuf, 0, cbuf.length, false)); cbuf = VALUE_491.toCharArray(); assertTrue(NumberInput.inLongRange(cbuf, 0, cbuf.length, true)); assertTrue(NumberInput.inLongRange(cbuf, 0, cbuf.length, false)); cbuf = OVERFLOW.toCharArray(); assertFalse(NumberInput.inLongRange(cbuf, 0, cbuf.length, true)); assertFalse(NumberInput.inLongRange(cbuf, 0, cbuf.length, false)); }
public Date parse(String paramString, ParsePosition paramParsePosition) { if (looksLikeISO8601(paramString)) return parseAsISO8601(paramString, paramParsePosition); int i = paramString.length(); int j; do { i--; if (i < 0) break; j = paramString.charAt(i); } while (((j < 48) || (j > 57)) && ((i <= 0) && (j == 45))); if ((i < 0) && (NumberInput.inLongRange(paramString, false))) return new Date(Long.parseLong(paramString)); return parseAsRFC1123(paramString, paramParsePosition); }
private void _parseSlowInt(int expType, char[] buf, int offset, int len) throws IOException, JsonParseException { String numStr = _textBuffer.contentsAsString(); try { // [JACKSON-230] Some long cases still... if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) { // Probably faster to construct a String, call parse, than to use BigInteger _numberLong = Long.parseLong(numStr); _numTypesValid = NR_LONG; } else { // nope, need the heavy guns... (rare case) _numberBigInt = new BigInteger(numStr); _numTypesValid = NR_BIGINT; } } catch (NumberFormatException nex) { // Can this ever occur? Due to overflow, maybe? _wrapError("Malformed numeric value '"+numStr+"'", nex); } }
protected void convertNumberToBigDecimal() throws IOException, JsonParseException { /* 05-Aug-2008, tatus: Important note: this MUST start with * more accurate representations, since we don't know which * value is the original one (others get generated when * requested) */ if ((_numTypesValid & NR_DOUBLE) != 0) { /* Let's actually parse from String representation, * to avoid rounding errors that non-decimal floating operations * would incur */ _numberBigDecimal = NumberInput.parseBigDecimal(getText()); } else if ((_numTypesValid & NR_BIGINT) != 0) { _numberBigDecimal = new BigDecimal(_numberBigInt); } else if ((_numTypesValid & NR_LONG) != 0) { _numberBigDecimal = BigDecimal.valueOf(_numberLong); } else if ((_numTypesValid & NR_INT) != 0) { _numberBigDecimal = BigDecimal.valueOf(_numberInt); } else { _throwInternal(); } _numTypesValid |= NR_BIGDECIMAL; }
private void _parseSlowIntValue(int expType, char[] buf, int offset, int len) throws IOException, JsonParseException { String numStr = _textBuffer.contentsAsString(); try { // [JACKSON-230] Some long cases still... if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) { // Probably faster to construct a String, call parse, than to use BigInteger _numberLong = Long.parseLong(numStr); _numTypesValid = NR_LONG; } else { // nope, need the heavy guns... (rare case) _numberBigInt = new BigInteger(numStr); _numTypesValid = NR_BIGINT; } } catch (NumberFormatException nex) { // Can this ever occur? Due to overflow, maybe? _wrapError("Malformed numeric value '"+numStr+"'", nex); } }
private Long rangeCheckedLong(JsonParser parser, DeserializationContext context) throws IOException { String text = parser.getText().trim(); if (text.length() == 0) { return null; } try { return Long.valueOf(NumberInput.parseLong(text)); } catch (Exception e) { throw context.weirdStringException(//NOSONAR _valueClass, "Over/underflow: numeric value (" + text +") out of range of Long (" + Long.MIN_VALUE + " to " + Long.MAX_VALUE + ")" ); } }
protected final long _parseLongPrimitive(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { return jp.getLongValue(); } if (t == JsonToken.VALUE_STRING) { String text = jp.getText().trim(); if (text.length() == 0) { return 0L; } try { return NumberInput.parseLong(text); } catch (IllegalArgumentException iae) { } throw ctxt.weirdStringException(text, _valueClass, "not a valid long value"); } if (t == JsonToken.VALUE_NULL) { return 0L; } throw ctxt.mappingException(_valueClass, t); }
@Override public Date parse(String dateStr, ParsePosition pos) { if (looksLikeISO8601(dateStr)) { // also includes "plain" return parseAsISO8601(dateStr, pos); } /* 14-Feb-2010, tatu: As per [JACKSON-236], better also * consider "stringified" simple time stamp */ int i = dateStr.length(); while (--i >= 0) { char ch = dateStr.charAt(i); if (ch < '0' || ch > '9') break; } if (i < 0) { // all digits if (NumberInput.inLongRange(dateStr, false)) { return new Date(Long.parseLong(dateStr)); } } // Otherwise, fall back to using RFC 1123 return parseAsRFC1123(dateStr, pos); }
@Override public int getValueAsInt(int defaultValue) throws IOException, JsonParseException { if (_currToken != null) { switch (_currToken) { case VALUE_NUMBER_INT: case VALUE_NUMBER_FLOAT: return getIntValue(); case VALUE_TRUE: return 1; case VALUE_FALSE: case VALUE_NULL: return 0; case VALUE_STRING: return NumberInput.parseAsInt(getText(), defaultValue); case VALUE_EMBEDDED_OBJECT: { Object value = this.getEmbeddedObject(); if (value instanceof Number) { return ((Number) value).intValue(); } } } } return defaultValue; }
@Override public long getValueAsLong(long defaultValue) throws IOException, JsonParseException { if (_currToken != null) { switch (_currToken) { case VALUE_NUMBER_INT: case VALUE_NUMBER_FLOAT: return getLongValue(); case VALUE_TRUE: return 1; case VALUE_FALSE: case VALUE_NULL: return 0; case VALUE_STRING: return NumberInput.parseAsLong(getText(), defaultValue); case VALUE_EMBEDDED_OBJECT: { Object value = this.getEmbeddedObject(); if (value instanceof Number) { return ((Number) value).longValue(); } } } } return defaultValue; }
@Override public double getValueAsDouble(double defaultValue) throws IOException, JsonParseException { if (_currToken != null) { switch (_currToken) { case VALUE_NUMBER_INT: case VALUE_NUMBER_FLOAT: return getDoubleValue(); case VALUE_TRUE: return 1; case VALUE_FALSE: case VALUE_NULL: return 0; case VALUE_STRING: return NumberInput.parseAsDouble(getText(), defaultValue); case VALUE_EMBEDDED_OBJECT: { Object value = this.getEmbeddedObject(); if (value instanceof Number) { return ((Number) value).doubleValue(); } } } } return defaultValue; }
private final static int _parseIndex(String str) { final int len = str.length(); // [core#133]: beware of super long indexes; assume we never // have arrays over 2 billion entries so ints are fine. if (len == 0 || len > 10) { return -1; } // [core#176]: no leading zeroes allowed char c = str.charAt(0); if (c <= '0') { return (len == 1 && c == '0') ? 0 : -1; } if (c > '9') { return -1; } for (int i = 1; i < len; ++i) { c = str.charAt(i); if (c > '9' || c < '0') { return -1; } } if (len == 10) { long l = NumberInput.parseLong(str); if (l > Integer.MAX_VALUE) { return -1; } } return NumberInput.parseInt(str); }
@Override public int getValueAsInt(int defaultValue) throws IOException { JsonToken t = _currToken; if ((t == JsonToken.VALUE_NUMBER_INT) || (t == JsonToken.VALUE_NUMBER_FLOAT)) { return getIntValue(); } if (t != null) { switch (t.id()) { case ID_STRING: String str = getText(); if (_hasTextualNull(str)) { return 0; } return NumberInput.parseAsInt(str, defaultValue); case ID_TRUE: return 1; case ID_FALSE: return 0; case ID_NULL: return 0; case ID_EMBEDDED_OBJECT: Object value = getEmbeddedObject(); if (value instanceof Number) { return ((Number) value).intValue(); } } } return defaultValue; }
@Override public long getValueAsLong(long defaultValue) throws IOException { JsonToken t = _currToken; if ((t == JsonToken.VALUE_NUMBER_INT) || (t == JsonToken.VALUE_NUMBER_FLOAT)) { return getLongValue(); } if (t != null) { switch (t.id()) { case ID_STRING: String str = getText(); if (_hasTextualNull(str)) { return 0L; } return NumberInput.parseAsLong(str, defaultValue); case ID_TRUE: return 1L; case ID_FALSE: case ID_NULL: return 0L; case ID_EMBEDDED_OBJECT: Object value = getEmbeddedObject(); if (value instanceof Number) { return ((Number) value).longValue(); } } } return defaultValue; }
@Override public double getValueAsDouble(double defaultValue) throws IOException { JsonToken t = _currToken; if (t != null) { switch (t.id()) { case ID_STRING: String str = getText(); if (_hasTextualNull(str)) { return 0L; } return NumberInput.parseAsDouble(str, defaultValue); case ID_NUMBER_INT: case ID_NUMBER_FLOAT: return getDoubleValue(); case ID_TRUE: return 1.0; case ID_FALSE: case ID_NULL: return 0.0; case ID_EMBEDDED_OBJECT: Object value = this.getEmbeddedObject(); if (value instanceof Number) { return ((Number) value).doubleValue(); } } } return defaultValue; }
/** * Specialized convenience method that will decode a 32-bit int, * of at most 9 digits (and possible leading minus sign). * * @param neg Whether contents start with a minus sign * * @since 2.9 */ public int contentsAsInt(boolean neg) { if ((_inputStart >= 0) && (_inputBuffer != null)) { if (neg) { return -NumberInput.parseInt(_inputBuffer, _inputStart+1, _inputLen-1); } return NumberInput.parseInt(_inputBuffer, _inputStart, _inputLen); } if (neg) { return -NumberInput.parseInt(_currentSegment, 1, _currentSize-1); } return NumberInput.parseInt(_currentSegment, 0, _currentSize); }
/** * Specialized convenience method that will decode a 64-bit int, * of at most 18 digits (and possible leading minus sign). * * @param neg Whether contents start with a minus sign * * @since 2.9 */ public long contentsAsLong(boolean neg) { if ((_inputStart >= 0) && (_inputBuffer != null)) { if (neg) { return -NumberInput.parseLong(_inputBuffer, _inputStart+1, _inputLen-1); } return NumberInput.parseLong(_inputBuffer, _inputStart, _inputLen); } if (neg) { return -NumberInput.parseLong(_currentSegment, 1, _currentSize-1); } return NumberInput.parseLong(_currentSegment, 0, _currentSize); }
public void testIntParsingWithStrings() throws Exception { assertEquals(3, NumberInput.parseInt("3")); assertEquals(0, NumberInput.parseInt("0")); assertEquals(-3, NumberInput.parseInt("-3")); assertEquals(27, NumberInput.parseInt("27")); assertEquals(-31, NumberInput.parseInt("-31")); assertEquals(271, NumberInput.parseInt("271")); assertEquals(-131, NumberInput.parseInt("-131")); assertEquals(2709, NumberInput.parseInt("2709")); assertEquals(-9999, NumberInput.parseInt("-9999")); assertEquals(Integer.MIN_VALUE, NumberInput.parseInt(""+Integer.MIN_VALUE)); assertEquals(Integer.MAX_VALUE, NumberInput.parseInt(""+Integer.MAX_VALUE)); }
public void testContentsAsDecimalThrowsNumberFormatException() { TextBuffer textBuffer = new TextBuffer( null); try { textBuffer.contentsAsDecimal(); fail("Expecting exception: NumberFormatException"); } catch(NumberFormatException e) { assertEquals(NumberInput.class.getName(), e.getStackTrace()[0].getClassName()); } }
/** Parses a long out of the input, using the optimized path when the value is not quoted. */ private static long parseLong(JsonParser parser) throws IOException { if (parser.currentToken() == JsonToken.VALUE_NUMBER_INT) { return parser.getLongValue(); } return NumberInput.parseLong(parser.getText()); }
@Override public int getValueAsInt(int defaultValue) throws IOException, JsonParseException { JsonToken t = _currToken; if (t != null) { switch (t.id()) { case ID_STRING: String str = getText(); if (_hasTextualNull(str)) { return 0; } return NumberInput.parseAsInt(str, defaultValue); case ID_NUMBER_INT: case ID_NUMBER_FLOAT: return getIntValue(); case ID_TRUE: return 1; case ID_FALSE: return 0; case ID_NULL: return 0; case ID_EMBEDDED_OBJECT: Object value = this.getEmbeddedObject(); if (value instanceof Number) { return ((Number) value).intValue(); } } } return defaultValue; }
@Override public long getValueAsLong(long defaultValue) throws IOException, JsonParseException { JsonToken t = _currToken; if (t != null) { switch (t.id()) { case ID_STRING: String str = getText(); if (_hasTextualNull(str)) { return 0L; } return NumberInput.parseAsLong(str, defaultValue); case ID_NUMBER_INT: case ID_NUMBER_FLOAT: return getLongValue(); case ID_TRUE: return 1L; case ID_FALSE: case ID_NULL: return 0L; case ID_EMBEDDED_OBJECT: Object value = this.getEmbeddedObject(); if (value instanceof Number) { return ((Number) value).longValue(); } } } return defaultValue; }
@Override public double getValueAsDouble(double defaultValue) throws IOException, JsonParseException { JsonToken t = _currToken; if (t != null) { switch (t.id()) { case ID_STRING: String str = getText(); if (_hasTextualNull(str)) { return 0L; } return NumberInput.parseAsDouble(str, defaultValue); case ID_NUMBER_INT: case ID_NUMBER_FLOAT: return getDoubleValue(); case ID_TRUE: return 1.0; case ID_FALSE: case ID_NULL: return 0.0; case ID_EMBEDDED_OBJECT: Object value = this.getEmbeddedObject(); if (value instanceof Number) { return ((Number) value).doubleValue(); } } } return defaultValue; }
@Override public Integer deserialize(JsonParser parser, DeserializationContext context) throws IOException { JsonToken t = parser.getCurrentToken(); if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too return rangeCheckedInteger(parser, context); } if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse String text = parser.getText().trim(); try { int len = text.length(); if (len > 9) { return rangeCheckedInteger(parser, context); } if (len == 0) { return null; } return Integer.valueOf(NumberInput.parseInt(text)); } catch (IllegalArgumentException iae) { throw context.weirdStringException(_valueClass, "not a valid Integer value");//NOSONAR } } if (t == JsonToken.VALUE_NULL) { return null; } // Otherwise, no can do: throw context.mappingException(_valueClass); }
@Override protected Byte _parseByte(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonToken t = jp.getCurrentToken(); Integer value = null; if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too value = jp.getIntValue(); } else if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse String text = jp.getText().trim(); try { int len = text.length(); if (len == 0) { return getEmptyValue(); } value = NumberInput.parseInt(text); } catch (IllegalArgumentException iae) { throw ctxt.weirdStringException(_valueClass, "not a valid Byte value");//NOSONAR } } if (value != null) { // So far so good: but does it fit? if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { throw ctxt.weirdStringException(_valueClass, "overflow, value can not be represented as 8-bit value"); } return (byte) (int) value; } if (t == JsonToken.VALUE_NULL) { return getNullValue(); } throw ctxt.mappingException(_valueClass, t); }
protected Byte _parseByte(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too return jp.getByteValue(); } if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse String text = jp.getText().trim(); int value; try { int len = text.length(); if (len == 0) { return (Byte) getEmptyValue(); } value = NumberInput.parseInt(text); } catch (IllegalArgumentException iae) { throw ctxt.weirdStringException(text, _valueClass, "not a valid Byte value"); } // So far so good: but does it fit? // as per [JACKSON-804], allow range up to 255, inclusive if (value < Byte.MIN_VALUE || value > 255) { throw ctxt.weirdStringException(text, _valueClass, "overflow, value can not be represented as 8-bit value"); } return Byte.valueOf((byte) value); } if (t == JsonToken.VALUE_NULL) { return (Byte) getNullValue(); } throw ctxt.mappingException(_valueClass, t); }
protected Short _parseShort(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too return jp.getShortValue(); } if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse String text = jp.getText().trim(); int value; try { int len = text.length(); if (len == 0) { return (Short) getEmptyValue(); } value = NumberInput.parseInt(text); } catch (IllegalArgumentException iae) { throw ctxt.weirdStringException(text, _valueClass, "not a valid Short value"); } // So far so good: but does it fit? if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { throw ctxt.weirdStringException(text, _valueClass, "overflow, value can not be represented as 16-bit value"); } return Short.valueOf((short) value); } if (t == JsonToken.VALUE_NULL) { return (Short) getNullValue(); } throw ctxt.mappingException(_valueClass, t); }
protected final int _parseIntPrimitive(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); // Int works as is, coercing fine as well if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too return jp.getIntValue(); } if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse /* 31-Dec-2009, tatus: Should improve handling of overflow * values... but this'll have to do for now */ String text = jp.getText().trim(); try { int len = text.length(); if (len > 9) { long l = Long.parseLong(text); if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) { throw ctxt.weirdStringException(text, _valueClass, "Overflow: numeric value ("+text+") out of range of int ("+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE+")"); } return (int) l; } if (len == 0) { return 0; } return NumberInput.parseInt(text); } catch (IllegalArgumentException iae) { throw ctxt.weirdStringException(text, _valueClass, "not a valid int value"); } } if (t == JsonToken.VALUE_NULL) { return 0; } // Otherwise, no can do: throw ctxt.mappingException(_valueClass, t); }
protected final Integer _parseInteger(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too return Integer.valueOf(jp.getIntValue()); } if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse String text = jp.getText().trim(); try { int len = text.length(); if (len > 9) { long l = Long.parseLong(text); if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) { throw ctxt.weirdStringException(text, _valueClass, "Overflow: numeric value ("+text+") out of range of Integer ("+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE+")"); } return Integer.valueOf((int) l); } if (len == 0) { return (Integer) getEmptyValue(); } return Integer.valueOf(NumberInput.parseInt(text)); } catch (IllegalArgumentException iae) { throw ctxt.weirdStringException(text, _valueClass, "not a valid Integer value"); } } if (t == JsonToken.VALUE_NULL) { return (Integer) getNullValue(); } // Otherwise, no can do: throw ctxt.mappingException(_valueClass, t); }
protected final Long _parseLong(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); // it should be ok to coerce (although may fail, too) if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { return jp.getLongValue(); } // let's allow Strings to be converted too if (t == JsonToken.VALUE_STRING) { // !!! 05-Jan-2009, tatu: Should we try to limit value space, JDK is too lenient? String text = jp.getText().trim(); if (text.length() == 0) { return (Long) getEmptyValue(); } try { return Long.valueOf(NumberInput.parseLong(text)); } catch (IllegalArgumentException iae) { } throw ctxt.weirdStringException(text, _valueClass, "not a valid Long value"); } if (t == JsonToken.VALUE_NULL) { return (Long) getNullValue(); } // Otherwise, no can do: throw ctxt.mappingException(_valueClass, t); }
/** * Helper method for encapsulating calls to low-level double value parsing; single place * just because we need a work-around that must be applied to all calls. */ protected final static double parseDouble(String numStr) throws NumberFormatException { // [JACKSON-486]: avoid some nasty float representations... but should it be MIN_NORMAL or MIN_VALUE? // for now, MIN_VALUE, since MIN_NORMAL is JDK 1.6 if (NumberInput.NASTY_SMALL_DOUBLE.equals(numStr)) { return Double.MIN_VALUE; } return Double.parseDouble(numStr); }
public void testLongParsing() throws Exception { char[] testChars = "123456789012345678".toCharArray(); assertEquals(123456789012345678L, NumberInput.parseLong(testChars, 0, testChars.length)); }
protected double _parseDouble(String paramString) { return NumberInput.parseDouble(paramString); }
public final double asDouble(double paramDouble) { return NumberInput.parseAsDouble(this._value, paramDouble); }