Java 类com.fasterxml.jackson.core.JsonParser.NumberType 实例源码

项目:GitHub    文件:AsyncScalarArrayTest.java   
private void _testInts(JsonFactory f, int[] values,
        byte[] data, int offset, int readSize) throws IOException
{
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    // start with "no token"
    assertNull(r.currentToken());
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    for (int i = 0; i < values.length; ++i) {
        assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
        assertEquals(values[i], r.getIntValue());
        assertEquals(NumberType.INT, r.getNumberType());

        // and then couple of special modes, just to get better test coverage
        String asStr = String.valueOf(values[i]);
        assertEquals(asStr, r.currentText());
        StringWriter sw = new StringWriter();
        assertEquals(asStr.length(), r.parser().getText(sw));
        assertEquals(asStr, sw.toString());
    }
    assertToken(JsonToken.END_ARRAY, r.nextToken());

    // and end up with "no token" as well
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
项目:GitHub    文件:AsyncScalarArrayTest.java   
private void _testLong(JsonFactory f, long[] values,
        byte[] data, int offset, int readSize) throws IOException
{
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    // start with "no token"
    assertNull(r.currentToken());
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    for (int i = 0; i < values.length; ++i) {
        assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
        assertEquals(values[i], r.getLongValue());
        assertEquals(NumberType.LONG, r.getNumberType());
    }
    assertToken(JsonToken.END_ARRAY, r.nextToken());

    // and end up with "no token" as well
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
项目:GitHub    文件:AsyncScalarArrayTest.java   
private void _testFloats(JsonFactory f, float[] values,
        byte[] data, int offset, int readSize) throws IOException
{
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    // start with "no token"
    assertNull(r.currentToken());
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    for (int i = 0; i < values.length; ++i) {
        assertToken(JsonToken.VALUE_NUMBER_FLOAT, r.nextToken());
        assertEquals(values[i], r.getFloatValue());
        // json can't distinguish floats from doubles so
        assertEquals(NumberType.DOUBLE, r.getNumberType());
    }
    assertToken(JsonToken.END_ARRAY, r.nextToken());
    // and end up with "no token" as well
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
项目:GitHub    文件:AsyncScalarArrayTest.java   
private void _testDoubles(JsonFactory f, double[] values,
        byte[] data, int offset, int readSize) throws IOException
{
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    // start with "no token"
    assertNull(r.currentToken());
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    for (int i = 0; i < values.length; ++i) {
        assertToken(JsonToken.VALUE_NUMBER_FLOAT, r.nextToken());
        assertEquals(String.format("Entry #%d: %s (textual '%s')",
                i, values[i], r.currentText()),
                values[i], r.getDoubleValue());
        assertEquals(NumberType.DOUBLE, r.getNumberType());
    }
    assertToken(JsonToken.END_ARRAY, r.nextToken());

    // and end up with "no token" as well
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
项目:GitHub    文件:AsyncScalarArrayTest.java   
private void _testBigIntegers(JsonFactory f, BigInteger[] values,
        byte[] data, int offset, int readSize) throws IOException
{
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    // start with "no token"
    assertNull(r.currentToken());
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    for (int i = 0; i < values.length; ++i) {
        BigInteger expValue = values[i];
        assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
        assertEquals(expValue, r.getBigIntegerValue());
        assertEquals(NumberType.BIG_INTEGER, r.getNumberType());
    }
    assertToken(JsonToken.END_ARRAY, r.nextToken());
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
项目:GitHub    文件:AsyncScalarArrayTest.java   
private void _testBigDecimals(JsonFactory f, BigDecimal[] values,
        byte[] doc, int offset, int readSize) throws IOException
{
    AsyncReaderWrapper r = asyncForBytes(f, readSize, doc, offset);
    // start with "no token"
    assertNull(r.currentToken());
    assertToken(JsonToken.START_ARRAY, r.nextToken());
    for (int i = 0; i < values.length; ++i) {
        BigDecimal expValue = values[i];
        assertToken(JsonToken.VALUE_NUMBER_FLOAT, r.nextToken());
        assertEquals(expValue, r.getDecimalValue());
        assertEquals(NumberType.BIG_DECIMAL, r.getNumberType());
    }
    assertToken(JsonToken.END_ARRAY, r.nextToken());
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
项目:JSONQuery    文件:LeExpression.java   
protected boolean doLe(JsonNode propertyNode, JsonNode passedNode){
    if(propertyNode.isNumber() && passedNode.isNumber() && propertyNode.numberType() == passedNode.numberType()) {
        Number propertyValue = propertyNode.numberValue();
        Number passedValue = passedNode.numberValue();
        if(propertyNode.numberType() == NumberType.INT) {
            return ((Integer) propertyValue <= (Integer) passedValue);
        } else if(propertyNode.numberType() == NumberType.LONG) {
            return ((Long) propertyValue <= (Long) passedValue);
        } else if(propertyNode.numberType() == NumberType.FLOAT) {
            return ((Float) propertyValue <= (Float) passedValue);
        } else if(propertyNode.numberType() == NumberType.DOUBLE) {
            return ((Double) propertyValue <= (Double) passedValue);
        } else {
            throw new UnsupportedExprException("Le supports only INT, LONG, DOUBLE, FLOAT values");
        }
    } else {
        throw new UnsupportedExprException("Le supports only numeric values of same type for comparison");
    }
}
项目:JSONQuery    文件:GtExpression.java   
protected boolean doGt(JsonNode propertyNode, JsonNode passedNode){
    if(propertyNode.isNumber() && passedNode.isNumber() && propertyNode.numberType() == passedNode.numberType()) {
        Number propertyValue = propertyNode.numberValue();
        Number passedValue = passedNode.numberValue();
        if(propertyNode.numberType() == NumberType.INT) {
            return ((Integer) propertyValue > (Integer) passedValue);
        } else if(propertyNode.numberType() == NumberType.LONG) {
            return ((Long) propertyValue > (Long) passedValue);
        } else if(propertyNode.numberType() == NumberType.FLOAT) {
            return ((Float) propertyValue > (Float) passedValue);
        } else if(propertyNode.numberType() == NumberType.DOUBLE) {
            return ((Double) propertyValue > (Double) passedValue);
        } else {
            throw new UnsupportedExprException("Gt supports only INT, LONG, DOUBLE, FLOAT values");
        }
    } else {
        throw new UnsupportedExprException("Gt supports only numeric values of same type for comparison");
    }
}
项目:JSONQuery    文件:LtExpression.java   
protected boolean doLt(JsonNode propertyNode, JsonNode passedNode){
    if(propertyNode.isNumber() && passedNode.isNumber() && propertyNode.numberType() == passedNode.numberType()) {
        Number propertyValue = propertyNode.numberValue();
        Number passedValue = passedNode.numberValue();
        if(propertyNode.numberType() == NumberType.INT) {
            return ((Integer) propertyValue < (Integer) passedValue);
        } else if(propertyNode.numberType() == NumberType.LONG) {
            return ((Long) propertyValue < (Long) passedValue);
        } else if(propertyNode.numberType() == NumberType.FLOAT) {
            return ((Float) propertyValue < (Float) passedValue);
        } else if(propertyNode.numberType() == NumberType.DOUBLE) {
            return ((Double) propertyValue < (Double) passedValue);
        } else {
            throw new UnsupportedExprException("Lt supports only INT, LONG, DOUBLE, FLOAT values");
        }
    } else {
        throw new UnsupportedExprException("Lt supports only numeric values of same type for comparison");
    }
}
项目:JSONQuery    文件:GeExpression.java   
private boolean doGe(JsonNode propertyNode, JsonNode passedNode){
    if(propertyNode.isNumber() && passedNode.isNumber() && propertyNode.numberType() == passedNode.numberType()) {
        Number propertyValue = propertyNode.numberValue();
        Number passedValue = passedNode.numberValue();
        if(propertyNode.numberType() == NumberType.INT) {
            return ((Integer) propertyValue >= (Integer) passedValue);
        } else if(propertyNode.numberType() == NumberType.LONG) {
            return ((Long) propertyValue >= (Long) passedValue);
        } else if(propertyNode.numberType() == NumberType.FLOAT) {
            return ((Float) propertyValue >= (Float) passedValue);
        } else if(propertyNode.numberType() == NumberType.DOUBLE) {
            return ((Double) propertyValue >=(Double) passedValue);
        } else {
            throw new UnsupportedExprException("Ge supports only INT, LONG, DOUBLE, FLOAT values");
        }
    } else {
        throw new UnsupportedExprException("Ge supports only numeric values of same type for comparison");
    }
}
项目:QuizUpWinner    文件:DateTimeSerializerBase.java   
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper paramJsonFormatVisitorWrapper, JavaType paramJavaType)
{
  boolean bool1 = this._useTimestamp;
  boolean bool2 = bool1;
  if ((!bool1) && (this._customFormat == null))
    bool2 = paramJsonFormatVisitorWrapper.getProvider().isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
  if (bool2)
  {
    JsonIntegerFormatVisitor localJsonIntegerFormatVisitor = paramJsonFormatVisitorWrapper.expectIntegerFormat(paramJavaType);
    if (localJsonIntegerFormatVisitor != null)
    {
      localJsonIntegerFormatVisitor.numberType(JsonParser.NumberType.LONG);
      localJsonIntegerFormatVisitor.format(JsonValueFormat.UTC_MILLISEC);
    }
    return;
  }
  JsonStringFormatVisitor localJsonStringFormatVisitor = paramJsonFormatVisitorWrapper.expectStringFormat(paramJavaType);
  if (localJsonStringFormatVisitor != null)
    localJsonStringFormatVisitor.format(JsonValueFormat.DATE_TIME);
}
项目:QuizUpWinner    文件:EnumSerializer.java   
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper paramJsonFormatVisitorWrapper, JavaType paramJavaType)
{
  if (paramJsonFormatVisitorWrapper.getProvider().isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX))
  {
    JsonIntegerFormatVisitor localJsonIntegerFormatVisitor = paramJsonFormatVisitorWrapper.expectIntegerFormat(paramJavaType);
    if (localJsonIntegerFormatVisitor != null)
      localJsonIntegerFormatVisitor.numberType(JsonParser.NumberType.INT);
    return;
  }
  JsonStringFormatVisitor localJsonStringFormatVisitor = paramJsonFormatVisitorWrapper.expectStringFormat(paramJavaType);
  if ((paramJavaType != null) && (localJsonStringFormatVisitor != null) && (paramJavaType.isEnumType()))
  {
    LinkedHashSet localLinkedHashSet = new LinkedHashSet();
    Iterator localIterator = this._values.values().iterator();
    while (localIterator.hasNext())
      localLinkedHashSet.add(((SerializedString)localIterator.next()).getValue());
    localJsonStringFormatVisitor.enumTypes(localLinkedHashSet);
  }
}
项目:QuizUpWinner    文件:StdDeserializer.java   
protected final boolean _parseBooleanFromNumber(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
{
  if (paramJsonParser.getNumberType() == JsonParser.NumberType.LONG)
  {
    Boolean localBoolean;
    if (paramJsonParser.getLongValue() == 0L)
      localBoolean = Boolean.FALSE;
    else
      localBoolean = Boolean.TRUE;
    return localBoolean.booleanValue();
  }
  String str = paramJsonParser.getText();
  if (("0.0".equals(str)) || ("0".equals(str)))
    return Boolean.FALSE.booleanValue();
  return Boolean.TRUE.booleanValue();
}
项目:QuizUpWinner    文件:StdDeserializer.java   
protected final boolean _parseBooleanPrimitive(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
{
  JsonToken localJsonToken = paramJsonParser.getCurrentToken();
  if (localJsonToken == JsonToken.VALUE_TRUE)
    return true;
  if (localJsonToken == JsonToken.VALUE_FALSE)
    return false;
  if (localJsonToken == JsonToken.VALUE_NULL)
    return false;
  if (localJsonToken == JsonToken.VALUE_NUMBER_INT)
  {
    if (paramJsonParser.getNumberType() == JsonParser.NumberType.INT)
      return paramJsonParser.getIntValue() != 0;
    return _parseBooleanFromNumber(paramJsonParser, paramDeserializationContext);
  }
  if (localJsonToken == JsonToken.VALUE_STRING)
  {
    String str = paramJsonParser.getText().trim();
    if ("true".equals(str))
      return true;
    if (("false".equals(str)) || (str.length() == 0))
      return Boolean.FALSE.booleanValue();
    throw paramDeserializationContext.weirdStringException(str, this._valueClass, "only \"true\" or \"false\" recognized");
  }
  throw paramDeserializationContext.mappingException(this._valueClass, localJsonToken);
}
项目:QuizUpWinner    文件:TokenBuffer.java   
public final JsonParser.NumberType getNumberType()
{
  Number localNumber = getNumberValue();
  if ((localNumber instanceof Integer))
    return JsonParser.NumberType.INT;
  if ((localNumber instanceof Long))
    return JsonParser.NumberType.LONG;
  if ((localNumber instanceof Double))
    return JsonParser.NumberType.DOUBLE;
  if ((localNumber instanceof BigDecimal))
    return JsonParser.NumberType.BIG_DECIMAL;
  if ((localNumber instanceof BigInteger))
    return JsonParser.NumberType.BIG_INTEGER;
  if ((localNumber instanceof Float))
    return JsonParser.NumberType.FLOAT;
  if ((localNumber instanceof Short))
    return JsonParser.NumberType.INT;
  return null;
}
项目:GitHub    文件:AsyncSimpleObjectTest.java   
private void _testNumbers(JsonFactory f,
        byte[] data, int offset, int readSize) throws IOException
{
    AsyncReaderWrapper r = asyncForBytes(f, readSize, data, offset);
    // start with "no token"
    assertNull(r.currentToken());
    assertToken(JsonToken.START_OBJECT, r.nextToken());

    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("i1", r.currentText());
    assertToken(JsonToken.VALUE_NUMBER_INT, r.nextToken());
    assertEquals(NumberType.INT, r.getNumberType());
    assertEquals(NUMBER_EXP_I, r.getIntValue());
    assertEquals((double)NUMBER_EXP_I, r.getDoubleValue());

    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("doubley", r.currentText());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, r.nextToken());
    assertEquals(NumberType.DOUBLE, r.getNumberType());
    assertEquals(NUMBER_EXP_D, r.getDoubleValue());
    assertEquals((long) NUMBER_EXP_D, r.getLongValue());

    assertToken(JsonToken.FIELD_NAME, r.nextToken());
    assertEquals("biggieDecimal", r.currentText());
    assertToken(JsonToken.VALUE_NUMBER_FLOAT, r.nextToken());
    // can't really tell double/BigDecimal apart in plain json
    assertEquals(NumberType.DOUBLE, r.getNumberType());
    assertEquals(NUMBER_EXP_BD, r.getDecimalValue());
    assertEquals(""+NUMBER_EXP_BD, r.currentText());

    assertToken(JsonToken.END_OBJECT, r.nextToken());

    // and end up with "no token" as well
    assertNull(r.nextToken());
    assertTrue(r.isClosed());
}
项目:openbd-core    文件:DeserializeJSONJackson.java   
private cfData  parseArray(JsonParser jp, cfArrayData array, boolean bStrictMapping ) throws JsonParseException, IOException, cfmRunTimeException{

    JsonToken   token   = jp.nextToken();
    while ( token != JsonToken.END_ARRAY ){

        if ( token == JsonToken.START_ARRAY ){
            array.addElement( parseArray(jp,cfArrayData.createArray(1),bStrictMapping ) );
        }else if ( token == JsonToken.START_OBJECT ){
            array.addElement( parseObject(jp,new cfStructData(),bStrictMapping) );
        }else if ( token == JsonToken.VALUE_NUMBER_INT ){

            if ( jp.getNumberType() == NumberType.INT )
                array.addElement( new cfNumberData(jp.getIntValue()) );
            else if ( jp.getNumberType() == NumberType.LONG || jp.getNumberType() == NumberType.BIG_INTEGER )
                array.addElement( new cfNumberData(jp.getLongValue()) );

        }else if ( token == JsonToken.VALUE_NUMBER_FLOAT ){

            if ( jp.getNumberType() == NumberType.FLOAT )
                array.addElement( new cfNumberData(jp.getFloatValue()) );
            else if ( jp.getNumberType() == NumberType.DOUBLE )
                array.addElement( new cfNumberData(jp.getDoubleValue()) );

        } else if ( token == JsonToken.VALUE_FALSE ){
            array.addElement( cfBooleanData.FALSE );
        } else if ( token == JsonToken.VALUE_TRUE ){
            array.addElement( cfBooleanData.TRUE );
        } else if ( token == JsonToken.VALUE_NULL ){
            array.addElement( cfNullData.NULL );
        }else
            array.addElement(  getString(jp.getText()) );

        token   = jp.nextToken();
    }

    return array;
}
项目:QuizUpWinner    文件:StdDeserializer.java   
protected final Boolean _parseBoolean(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
{
  JsonToken localJsonToken = paramJsonParser.getCurrentToken();
  if (localJsonToken == JsonToken.VALUE_TRUE)
    return Boolean.TRUE;
  if (localJsonToken == JsonToken.VALUE_FALSE)
    return Boolean.FALSE;
  if (localJsonToken == JsonToken.VALUE_NUMBER_INT)
  {
    if (paramJsonParser.getNumberType() == JsonParser.NumberType.INT)
    {
      if (paramJsonParser.getIntValue() == 0)
        return Boolean.FALSE;
      return Boolean.TRUE;
    }
    return Boolean.valueOf(_parseBooleanFromNumber(paramJsonParser, paramDeserializationContext));
  }
  if (localJsonToken == JsonToken.VALUE_NULL)
    return (Boolean)getNullValue();
  if (localJsonToken == JsonToken.VALUE_STRING)
  {
    String str = paramJsonParser.getText().trim();
    if ("true".equals(str))
      return Boolean.TRUE;
    if ("false".equals(str))
      return Boolean.FALSE;
    if (str.length() == 0)
      return (Boolean)getEmptyValue();
    throw paramDeserializationContext.weirdStringException(str, this._valueClass, "only \"true\" or \"false\" recognized");
  }
  throw paramDeserializationContext.mappingException(this._valueClass, localJsonToken);
}
项目:QuizUpWinner    文件:TokenBuffer.java   
public final BigInteger getBigIntegerValue()
{
  Number localNumber = getNumberValue();
  if ((localNumber instanceof BigInteger))
    return (BigInteger)localNumber;
  if (getNumberType() == JsonParser.NumberType.BIG_DECIMAL)
    return ((BigDecimal)localNumber).toBigInteger();
  return BigInteger.valueOf(localNumber.longValue());
}
项目:QuizUpWinner    文件:TreeTraversingParser.java   
public JsonParser.NumberType getNumberType()
{
  JsonNode localJsonNode = currentNumericNode();
  if (localJsonNode == null)
    return null;
  return localJsonNode.numberType();
}
项目:mev    文件:JsonImporter.java   
private Serializable getValue (JsonParser parser, JsonToken token) throws IOException {
  if (token != null) {
    switch (token) {
    case VALUE_STRING:
      return parser.getText ();
    case VALUE_NUMBER_INT:
      if (parser.getNumberType () == NumberType.INT || parser.getNumberType () == NumberType.LONG) {
        return Long.valueOf (parser.getLongValue ());
      } else {
        return parser.getNumberValue ();
      }
    case VALUE_NUMBER_FLOAT:
      if (parser.getNumberType () == NumberType.FLOAT) {
        return Float.valueOf (parser.getFloatValue ());
      } else if (parser.getNumberType () == NumberType.DOUBLE) {
        return Double.valueOf (parser.getDoubleValue ());
      } else {
        return parser.getNumberValue ();
      }
    case VALUE_TRUE:
      return Boolean.TRUE;
    case VALUE_FALSE:
      return Boolean.FALSE;
    case VALUE_NULL:
      return null;
    case END_ARRAY:
    default:
      break;
    }
  }
  return null;
}
项目:joyplus-tv    文件:StdDeserializer.java   
protected final boolean _parseBooleanPrimitive(JsonParser jp, DeserializationContext ctxt)
    throws IOException, JsonProcessingException
{
    JsonToken t = jp.getCurrentToken();
    if (t == JsonToken.VALUE_TRUE) {
        return true;
    }
    if (t == JsonToken.VALUE_FALSE) {
        return false;
    }
    if (t == JsonToken.VALUE_NULL) {
        return false;
    }
    // [JACKSON-78]: should accept ints too, (0 == false, otherwise true)
    if (t == JsonToken.VALUE_NUMBER_INT) {
        // 11-Jan-2012, tatus: May be outside of int...
        if (jp.getNumberType() == NumberType.INT) {
            return (jp.getIntValue() != 0);
        }
        return _parseBooleanFromNumber(jp, ctxt);
    }
    // And finally, let's allow Strings to be converted too
    if (t == JsonToken.VALUE_STRING) {
        String text = jp.getText().trim();
        if ("true".equals(text)) {
            return true;
        }
        if ("false".equals(text) || text.length() == 0) {
            return Boolean.FALSE;
        }
        throw ctxt.weirdStringException(text, _valueClass, "only \"true\" or \"false\" recognized");
    }
    // Otherwise, no can do:
    throw ctxt.mappingException(_valueClass, t);
}
项目:joyplus-tv    文件:StdDeserializer.java   
protected final Boolean _parseBoolean(JsonParser jp, DeserializationContext ctxt)
    throws IOException, JsonProcessingException
{
    JsonToken t = jp.getCurrentToken();
    if (t == JsonToken.VALUE_TRUE) {
        return Boolean.TRUE;
    }
    if (t == JsonToken.VALUE_FALSE) {
        return Boolean.FALSE;
    }
    // [JACKSON-78]: should accept ints too, (0 == false, otherwise true)
    if (t == JsonToken.VALUE_NUMBER_INT) {
        // 11-Jan-2012, tatus: May be outside of int...
        if (jp.getNumberType() == NumberType.INT) {
            return (jp.getIntValue() == 0) ? Boolean.FALSE : Boolean.TRUE;
        }
        return Boolean.valueOf(_parseBooleanFromNumber(jp, ctxt));
    }
    if (t == JsonToken.VALUE_NULL) {
        return (Boolean) getNullValue();
    }
    // And finally, let's allow Strings to be converted too
    if (t == JsonToken.VALUE_STRING) {
        String text = jp.getText().trim();
        if ("true".equals(text)) {
            return Boolean.TRUE;
        }
        if ("false".equals(text)) {
            return Boolean.FALSE;
        }
        if (text.length() == 0) {
            return (Boolean) getEmptyValue();
        }
        throw ctxt.weirdStringException(text, _valueClass, "only \"true\" or \"false\" recognized");
    }
    // Otherwise, no can do:
    throw ctxt.mappingException(_valueClass, t);
}
项目:joyplus-tv    文件:StdDeserializer.java   
protected final boolean _parseBooleanFromNumber(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException
{
    if (jp.getNumberType() == NumberType.LONG) {
        return (jp.getLongValue() == 0L) ? Boolean.FALSE : Boolean.TRUE;
    }
    // no really good logic; let's actually resort to textual comparison
    String str = jp.getText();
    if ("0.0".equals(str) || "0".equals(str)) {
        return Boolean.FALSE;
    }
    return Boolean.TRUE;
}
项目:GitHub    文件:TestDelegates.java   
@Override
public NumberType numberType() {
    return null;
}
项目:monarch    文件:JSONFormatter.java   
private void setNumberField(JsonParser jp, JSONToPdxMapper pih, String fieldName)
    throws IOException {
  try {
    NumberType nt = jp.getNumberType();

    switch (nt) {
      case BIG_DECIMAL:
        pih.addBigDecimalField(fieldName, jp.getDecimalValue());
        break;
      case BIG_INTEGER: {
        BigInteger bi = jp.getBigIntegerValue();
        pih.addBigIntegerField(fieldName, bi);
      }
        break;
      case DOUBLE:
        pih.addDoubleField(fieldName, jp.getDoubleValue());
        break;
      case FLOAT:
        pih.addFloatField(fieldName, jp.getFloatValue());
        break;
      case INT: {
        int val = jp.getIntValue();
        if (val > Short.MAX_VALUE || val < Short.MIN_VALUE) {
          pih.addIntField(fieldName, val);
        } else if (val > Byte.MAX_VALUE || val < Byte.MIN_VALUE) {
          pih.addShortField(fieldName, (short) val);
        } else {
          pih.addByteField(fieldName, (byte) val);
        }
      }
        break;
      case LONG:
        pih.addLongField(fieldName, jp.getLongValue());
        break;
      default:
        throw new IllegalStateException("setNumberField:unknow number type " + nt);
    }
  } catch (JsonParseException jpe) {
    throw jpe;
  } catch (IOException e) {
    throw e;
  }
}
项目:monarch    文件:JSONFormatter.java   
private void setNumberField(JsonParser jp, PdxListHelper pih) throws IOException {
  try {
    NumberType nt = jp.getNumberType();

    switch (nt) {
      case BIG_DECIMAL:
        pih.addBigDecimalField(jp.getDecimalValue());
        break;
      case BIG_INTEGER: {
        BigInteger bi = jp.getBigIntegerValue();
        pih.addBigIntegerField(bi);
      }
        break;
      case DOUBLE:
        pih.addDoubleField(jp.getDoubleValue());
        break;
      case FLOAT:
        pih.addFloatField(jp.getFloatValue());
        break;
      case INT: {
        int val = jp.getIntValue();
        if (val > Short.MAX_VALUE || val < Short.MIN_VALUE) {
          pih.addIntField(val);
        } else if (val > Byte.MAX_VALUE || val < Byte.MIN_VALUE) {
          pih.addShortField((short) val);
        } else {
          pih.addByteField((byte) val);
        }
      }
        break;
      case LONG:
        pih.addLongField(jp.getLongValue());
        break;
      default:
        throw new IllegalStateException("setNumberField:unknow number type " + nt);
    }
  } catch (JsonParseException jpe) {
    throw jpe;
  } catch (IOException e) {
    throw e;
  }
}
项目:openbd-core    文件:DeserializeJSONJackson.java   
private cfData  parseObject(JsonParser jp, cfStructData struct, boolean bStrictMapping ) throws JsonParseException, IOException, cfmRunTimeException{

    JsonToken   token   = jp.nextToken();
    while ( token != JsonToken.END_OBJECT ){
        String namefield = jp.getCurrentName();

        if ( token == JsonToken.START_ARRAY ){
            struct.setData( namefield, parseArray(jp, cfArrayData.createArray(1), bStrictMapping) );
        }else if ( token == JsonToken.START_OBJECT ){
            struct.setData( namefield, parseObject(jp,new cfStructData(), bStrictMapping) );
        }else if ( token == JsonToken.VALUE_NUMBER_INT ){

            if ( jp.getNumberType() == NumberType.INT )
                struct.setData( namefield, new cfNumberData(jp.getIntValue()) );
            else if ( jp.getNumberType() == NumberType.LONG || jp.getNumberType() == NumberType.BIG_INTEGER )
                struct.setData( namefield, new cfNumberData(jp.getLongValue()) );

        }else if ( token == JsonToken.VALUE_NUMBER_FLOAT ){

            if ( jp.getNumberType() == NumberType.FLOAT )
                struct.setData( namefield, new cfNumberData(jp.getFloatValue()) );
            else if ( jp.getNumberType() == NumberType.DOUBLE )
                struct.setData( namefield, new cfNumberData(jp.getDoubleValue()) );

        } else if ( token == JsonToken.VALUE_FALSE ){
            struct.setData( namefield, cfBooleanData.FALSE );
        } else if ( token == JsonToken.VALUE_TRUE ){
            struct.setData( namefield, cfBooleanData.TRUE );
        } else if ( token == JsonToken.VALUE_NULL ){
            struct.setData( namefield, cfNullData.NULL );
        }else{
            struct.setData( namefield, getString(jp.getText()) );
        }

        token   = jp.nextToken();
    }

    if ( bStrictMapping )
        return convertToQuery( struct );
    else
        return struct;
}
项目:QuizUpWinner    文件:StdJdkSerializers.java   
public final void acceptJsonFormatVisitor(JsonFormatVisitorWrapper paramJsonFormatVisitorWrapper, JavaType paramJavaType)
{
  JsonIntegerFormatVisitor localJsonIntegerFormatVisitor = paramJsonFormatVisitorWrapper.expectIntegerFormat(paramJavaType);
  if (localJsonIntegerFormatVisitor != null)
    localJsonIntegerFormatVisitor.numberType(JsonParser.NumberType.INT);
}
项目:QuizUpWinner    文件:StdJdkSerializers.java   
public final void acceptJsonFormatVisitor(JsonFormatVisitorWrapper paramJsonFormatVisitorWrapper, JavaType paramJavaType)
{
  JsonIntegerFormatVisitor localJsonIntegerFormatVisitor = paramJsonFormatVisitorWrapper.expectIntegerFormat(paramJavaType);
  if (localJsonIntegerFormatVisitor != null)
    localJsonIntegerFormatVisitor.numberType(JsonParser.NumberType.LONG);
}
项目:QuizUpWinner    文件:NumberSerializers.java   
public final void acceptJsonFormatVisitor(JsonFormatVisitorWrapper paramJsonFormatVisitorWrapper, JavaType paramJavaType)
{
  JsonNumberFormatVisitor localJsonNumberFormatVisitor = paramJsonFormatVisitorWrapper.expectNumberFormat(paramJavaType);
  if (localJsonNumberFormatVisitor != null)
    localJsonNumberFormatVisitor.numberType(JsonParser.NumberType.DOUBLE);
}
项目:QuizUpWinner    文件:NumberSerializers.java   
public final void acceptJsonFormatVisitor(JsonFormatVisitorWrapper paramJsonFormatVisitorWrapper, JavaType paramJavaType)
{
  JsonNumberFormatVisitor localJsonNumberFormatVisitor = paramJsonFormatVisitorWrapper.expectNumberFormat(paramJavaType);
  if (localJsonNumberFormatVisitor != null)
    localJsonNumberFormatVisitor.numberType(JsonParser.NumberType.FLOAT);
}
项目:QuizUpWinner    文件:NumberSerializers.java   
public final void acceptJsonFormatVisitor(JsonFormatVisitorWrapper paramJsonFormatVisitorWrapper, JavaType paramJavaType)
{
  JsonIntegerFormatVisitor localJsonIntegerFormatVisitor = paramJsonFormatVisitorWrapper.expectIntegerFormat(paramJavaType);
  if (localJsonIntegerFormatVisitor != null)
    localJsonIntegerFormatVisitor.numberType(JsonParser.NumberType.INT);
}
项目:QuizUpWinner    文件:NumberSerializers.java   
public final void acceptJsonFormatVisitor(JsonFormatVisitorWrapper paramJsonFormatVisitorWrapper, JavaType paramJavaType)
{
  JsonIntegerFormatVisitor localJsonIntegerFormatVisitor = paramJsonFormatVisitorWrapper.expectIntegerFormat(paramJavaType);
  if (localJsonIntegerFormatVisitor != null)
    localJsonIntegerFormatVisitor.numberType(JsonParser.NumberType.INT);
}
项目:QuizUpWinner    文件:NumberSerializers.java   
public final void acceptJsonFormatVisitor(JsonFormatVisitorWrapper paramJsonFormatVisitorWrapper, JavaType paramJavaType)
{
  JsonIntegerFormatVisitor localJsonIntegerFormatVisitor = paramJsonFormatVisitorWrapper.expectIntegerFormat(paramJavaType);
  if (localJsonIntegerFormatVisitor != null)
    localJsonIntegerFormatVisitor.numberType(JsonParser.NumberType.LONG);
}
项目:QuizUpWinner    文件:NumberSerializers.java   
public final void acceptJsonFormatVisitor(JsonFormatVisitorWrapper paramJsonFormatVisitorWrapper, JavaType paramJavaType)
{
  JsonNumberFormatVisitor localJsonNumberFormatVisitor = paramJsonFormatVisitorWrapper.expectNumberFormat(paramJavaType);
  if (localJsonNumberFormatVisitor != null)
    localJsonNumberFormatVisitor.numberType(JsonParser.NumberType.BIG_DECIMAL);
}
项目:QuizUpWinner    文件:NumberSerializers.java   
public final void acceptJsonFormatVisitor(JsonFormatVisitorWrapper paramJsonFormatVisitorWrapper, JavaType paramJavaType)
{
  JsonIntegerFormatVisitor localJsonIntegerFormatVisitor = paramJsonFormatVisitorWrapper.expectIntegerFormat(paramJavaType);
  if (localJsonIntegerFormatVisitor != null)
    localJsonIntegerFormatVisitor.numberType(JsonParser.NumberType.INT);
}
项目:QuizUpWinner    文件:JsonIntegerFormatVisitor.java   
public void numberType(JsonParser.NumberType paramNumberType)
{
}
项目:QuizUpWinner    文件:JsonNumberFormatVisitor.java   
public void numberType(JsonParser.NumberType paramNumberType)
{
}
项目:QuizUpWinner    文件:LongNode.java   
public final JsonParser.NumberType numberType()
{
  return JsonParser.NumberType.LONG;
}