當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonParser.getIntValue方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.core.JsonParser.getIntValue方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonParser.getIntValue方法的具體用法?Java JsonParser.getIntValue怎麽用?Java JsonParser.getIntValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.core.JsonParser的用法示例。


在下文中一共展示了JsonParser.getIntValue方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseInt32

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
/** Parsers an int32 value out of the input. */
static int parseInt32(JsonParser parser) throws IOException {
  JsonToken token = parser.currentToken();
  if (token == JsonToken.VALUE_NUMBER_INT) {
    // Use optimized code path for integral primitives, the normal case.
    return parser.getIntValue();
  }
  // JSON doesn't distinguish between integer values and floating point values so "1" and
  // "1.000" are treated as equal in JSON. For this reason we accept floating point values for
  // integer fields as well as long as it actually is an integer (i.e., round(value) == value).
  try {
    BigDecimal value =
        new BigDecimal(
            parser.getTextCharacters(), parser.getTextOffset(), parser.getTextLength());
    return value.intValueExact();
  } catch (Exception e) {
    throw new InvalidProtocolBufferException("Not an int32 value: " + parser.getText());
  }
}
 
開發者ID:curioswitch,項目名稱:curiostack,代碼行數:20,代碼來源:ParseSupport.java

示例2: parse

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public Integer parse(JsonParser jsonParser) throws IOException {
    if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {
        return null;
    } else {
        return jsonParser.getIntValue();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:IntegerMapper.java

示例3: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    switch(parser.getCurrentToken()) {
        case START_ARRAY:
            if(parser.nextToken() == JsonToken.END_ARRAY) {
                return null;
            }
            int year = parser.getIntValue();

            parser.nextToken();
            int month = parser.getIntValue();

            parser.nextToken();
            int day = parser.getIntValue();

            if(parser.nextToken() != JsonToken.END_ARRAY) {
                throw context.wrongTokenException(parser, JsonToken.END_ARRAY, "Expected array to end.");
            }
            return LocalDate.of(year, month, day);

        case VALUE_STRING:
            String string = parser.getText().trim();
            if(string.length() == 0) {
                return null;
            }
            return LocalDate.parse(string, ISO_DATE_OPTIONAL_TIME);
    }
    throw context.wrongTokenException(parser, JsonToken.START_ARRAY, "Expected array or string.");
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:30,代碼來源:JSR310LocalDateDeserializer.java

示例4: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public static ErrorMessage deserialize(JsonParser jp) throws IOException {
	jp.nextToken();
	int type = jp.getIntValue();

	jp.nextToken();
	long request = jp.getLongValue();

	jp.nextToken();
	ParserUtil.readObject(jp);

	jp.nextToken();
	String error = jp.getValueAsString();

	List<Object> arguments = null;
	JsonToken token = jp.nextToken();
	if (token == JsonToken.START_ARRAY) {
		arguments = ParserUtil.readArray(jp);
	}

	Map<String, Object> argumentsKw = null;
	token = jp.nextToken();
	if (token == JsonToken.START_OBJECT) {
		argumentsKw = ParserUtil.readObject(jp);
	}

	return new ErrorMessage(type, request, error, arguments, argumentsKw);
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:28,代碼來源:ErrorMessage.java

示例5: getValue

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Nullable
private static Object getValue(JsonParser jp) throws IOException {
	switch (jp.currentToken()) {
	case VALUE_FALSE:
	case VALUE_TRUE:
		return jp.getBooleanValue();
	case VALUE_STRING:
		return jp.getValueAsString();
	case VALUE_NUMBER_INT:
		switch (jp.getNumberType()) {
		case INT:
			return jp.getIntValue();
		case LONG:
			return jp.getLongValue();
		case BIG_INTEGER:
			return jp.getBigIntegerValue();
		default:
			return null;
		}
	case VALUE_NUMBER_FLOAT:
		switch (jp.getNumberType()) {
		case FLOAT:
			return jp.getFloatValue();
		case DOUBLE:
			return jp.getDoubleValue();
		case BIG_DECIMAL:
			return jp.getDecimalValue();
		default:
			return null;
		}
	default:
		return null;
	}
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:35,代碼來源:ParserUtil.java

示例6: unmarshall

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public BigDecimal unmarshall(JsonUnmarshallerContext unmarshallerContext) throws Exception {
    JsonParser parser = unmarshallerContext.getJsonParser();
    Unmarshaller<BigInteger, JsonUnmarshallerContext> bigIntegerUnmarshaller =
            unmarshallerContext.getUnmarshaller(BigInteger.class);

    JsonToken current = parser.getCurrentToken();
    if (current != JsonToken.START_ARRAY) {
        throw new SdkClientException("Invalid BigDecimal Format.");
    }
    parser.nextToken();
    int exponent = parser.getIntValue();
    parser.nextToken();
    BigInteger mantissa = bigIntegerUnmarshaller.unmarshall(unmarshallerContext);
    return new BigDecimal(mantissa, exponent);
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:16,代碼來源:SimpleTypeCborUnmarshallers.java

示例7: unmarshall

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
public BigDecimal unmarshall(JsonUnmarshallerContext unmarshallerContext) throws Exception {
    JsonParser parser = unmarshallerContext.getJsonParser();
    Unmarshaller<BigInteger, JsonUnmarshallerContext> bigIntegerUnmarshaller = unmarshallerContext.getUnmarshaller(BigInteger.class);

    JsonToken current = parser.getCurrentToken();
    if (current != JsonToken.START_ARRAY) {
        throw new SdkClientException("Invalid BigDecimal Format.");
    }
    parser.nextToken();
    int exponent = parser.getIntValue();
    parser.nextToken();
    BigInteger mantissa = bigIntegerUnmarshaller.unmarshall(unmarshallerContext);
    return new BigDecimal(mantissa, exponent);
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:15,代碼來源:SimpleTypeCborUnmarshallers.java

示例8: deserialize

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
@Override
public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException {
    switch(parser.getCurrentToken()) {
        case START_ARRAY:
            if(parser.nextToken() == JsonToken.END_ARRAY) {
                return null;
            }
            int year = parser.getIntValue();

            parser.nextToken();
            int month = parser.getIntValue();

            parser.nextToken();
            int day = parser.getIntValue();

            if(parser.nextToken() != JsonToken.END_ARRAY) {
                throw context.wrongTokenException(parser, JsonToken.END_ARRAY, "Expected array to end.");
            }
            return LocalDate.of(year, month, day);

        case VALUE_STRING:
            String string = parser.getText().trim();
            if(string.length() == 0) {
                return null;
            }
            return LocalDate.parse(string, ISO_DATE_OPTIONAL_TIME);
        default:
            throw context.wrongTokenException(parser, JsonToken.START_ARRAY, "Expected array or string.");
    }
}
 
開發者ID:klask-io,項目名稱:klask-io,代碼行數:31,代碼來源:JSR310LocalDateDeserializer.java

示例9: setNumberField

import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
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;
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:44,代碼來源:JSONFormatter.java


注:本文中的com.fasterxml.jackson.core.JsonParser.getIntValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。