本文整理汇总了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());
}
}
示例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();
}
}
示例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.");
}
示例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);
}
示例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;
}
}
示例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);
}
示例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);
}
示例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.");
}
}
示例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;
}
}