当前位置: 首页>>代码示例>>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;未经允许,请勿转载。