本文整理匯總了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;
}
}