Exemplo n.º 1
0
 @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);
 }
Exemplo n.º 2
0
 @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);
 }
Exemplo n.º 3
0
 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
             + ")");
   }
 }
Exemplo n.º 4
0
 public int asInt(int i) {
   return NumberInput.parseAsInt(_value, i);
 }
Exemplo n.º 5
0
 public double asDouble(double d) {
   return NumberInput.parseAsDouble(_value, d);
 }