本文整理汇总了Java中com.fasterxml.jackson.core.JsonToken.VALUE_NUMBER_INT属性的典型用法代码示例。如果您正苦于以下问题:Java JsonToken.VALUE_NUMBER_INT属性的具体用法?Java JsonToken.VALUE_NUMBER_INT怎么用?Java JsonToken.VALUE_NUMBER_INT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.fasterxml.jackson.core.JsonToken
的用法示例。
在下文中一共展示了JsonToken.VALUE_NUMBER_INT属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseInt32
/** 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: objectBytes
@Override
public Object objectBytes() throws IOException {
JsonToken currentToken = parser.getCurrentToken();
if (currentToken == JsonToken.VALUE_STRING) {
return utf8Bytes();
} else if (currentToken == JsonToken.VALUE_NUMBER_INT || currentToken == JsonToken.VALUE_NUMBER_FLOAT) {
return parser.getNumberValue();
} else if (currentToken == JsonToken.VALUE_TRUE) {
return Boolean.TRUE;
} else if (currentToken == JsonToken.VALUE_FALSE) {
return Boolean.FALSE;
} else if (currentToken == JsonToken.VALUE_NULL) {
return null;
} else {
//TODO should this really do UTF-8 conversion?
return utf8Bytes();
}
}
示例3: objectText
@Override
public Object objectText() throws IOException {
JsonToken currentToken = parser.getCurrentToken();
if (currentToken == JsonToken.VALUE_STRING) {
return text();
} else if (currentToken == JsonToken.VALUE_NUMBER_INT || currentToken == JsonToken.VALUE_NUMBER_FLOAT) {
return parser.getNumberValue();
} else if (currentToken == JsonToken.VALUE_TRUE) {
return Boolean.TRUE;
} else if (currentToken == JsonToken.VALUE_FALSE) {
return Boolean.FALSE;
} else if (currentToken == JsonToken.VALUE_NULL) {
return null;
} else {
return text();
}
}
示例4: write
private void write(BigIntWriter writer, JsonToken token, JsonParser parser) throws IOException {
if (token == JsonToken.VALUE_NUMBER_INT) {
writer.writeBigInt(parser.getLongValue());
} else {
try {
writer.writeBigInt(Long.parseLong(parser.getValueAsString()));
} catch (Exception ex1){
try {
// it is possible that we need to coerce a float to an integer.
writer.writeBigInt((long) Double.parseDouble(parser.getValueAsString()));
} catch (Exception ex2){
throw ex1;
}
}
}
}
示例5: readRecord
Map<String, Object> readRecord(JsonParser jp) throws IOException {
Map<String, Object> record = new HashMap<>();
String fielName = "";
Object value;
JsonToken token;
while((token = jp.nextToken()) != JsonToken.END_OBJECT) {
if (token == JsonToken.FIELD_NAME) {
fielName = jp.getCurrentName();
} else if (token == JsonToken.VALUE_STRING) {
value = jp.getValueAsString();
record.put(fielName, value);
} else if (token == JsonToken.VALUE_NUMBER_INT) {
value = jp.getValueAsLong();
record.put(fielName, value);
}
}
//System.out.println(record.toString());
return record;
}
示例6: acceptInteger
private Integer acceptInteger(JsonToken token) throws Exception {
if (token == JsonToken.VALUE_NUMBER_INT) {
int value = parser.getIntValue();
parser.nextToken();
return value;
} else {
throw new JSONException("syntax error, expect string, actual " + parser.getCurrentToken());
}
}
示例7: getToken
private JsonToken getToken(final ValueType type, final VPackSlice value) {
final JsonToken token;
switch (type) {
case OBJECT:
token = JsonToken.START_OBJECT;
break;
case ARRAY:
token = JsonToken.START_ARRAY;
break;
case STRING:
token = JsonToken.VALUE_STRING;
break;
case BOOL:
token = value.isTrue() ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
break;
case DOUBLE:
token = JsonToken.VALUE_NUMBER_FLOAT;
break;
case INT:
case SMALLINT:
case UINT:
token = JsonToken.VALUE_NUMBER_INT;
break;
case NULL:
token = JsonToken.VALUE_NULL;
break;
default:
token = null;
break;
}
return token;
}
示例8: getJsonToken
private JsonToken getJsonToken() {
if (reader.isNullValue()) {
return JsonToken.VALUE_NULL;
}
IonType currentType = reader.getType();
switch (currentType) {
case BLOB:
case CLOB:
return JsonToken.VALUE_EMBEDDED_OBJECT;
case BOOL:
return reader.booleanValue() ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
case DECIMAL:
return JsonToken.VALUE_NUMBER_FLOAT;
case FLOAT:
return JsonToken.VALUE_NUMBER_FLOAT;
case INT:
return JsonToken.VALUE_NUMBER_INT;
case LIST:
return JsonToken.START_ARRAY;
case SEXP:
return JsonToken.START_ARRAY;
case STRING:
return JsonToken.VALUE_STRING;
case STRUCT:
return JsonToken.START_OBJECT;
case SYMBOL:
return JsonToken.VALUE_STRING;
case TIMESTAMP:
return JsonToken.VALUE_EMBEDDED_OBJECT;
default:
throw new SdkClientException(String.format("Unhandled Ion type %s", currentType));
}
}
示例9: unmarshall
public BigInteger unmarshall(JsonUnmarshallerContext unmarshallerContext) throws Exception {
JsonParser parser = unmarshallerContext.getJsonParser();
JsonToken current = parser.getCurrentToken();
if (current == JsonToken.VALUE_NUMBER_INT) {
return parser.getBigIntegerValue();
} else if (current == JsonToken.VALUE_EMBEDDED_OBJECT) {
Object embedded = parser.getEmbeddedObject();
return new BigInteger((byte[]) embedded);
} else {
throw new SdkClientException("Invalid BigInteger Format.");
}
}
示例10: jsonToColumnValue
@Override
public Value jsonToColumnValue(final JsonParser parser, final ValueMetadata metadata) throws IOException {
JsonToken token;
Value value;
// Go to the next token
token = parser.nextToken();
if (token != JsonToken.VALUE_NUMBER_INT && token != JsonToken.VALUE_NULL) {
throw new IOException("Unable to parse field " + metadata.getName() + " expected int or null at line " + parser.getCurrentLocation().getLineNr());
}
// Can be a integer or null
if (token == JsonToken.VALUE_NUMBER_INT) {
value = new Value(parser.getValueAsLong(), metadata);
} else {
// null
if (metadata.isNotNull()) {
throw new IOException("Unable to parse field " + metadata.getName() + " expected int bu found null at line " + parser.getCurrentLocation().getLineNr());
}
value = new Value(metadata);
}
return value;
}
示例11: readNextTokenAsInt
private Integer readNextTokenAsInt() throws IOException {
if (mJp.nextToken() != JsonToken.VALUE_NUMBER_INT) {
if (mJp.getCurrentToken() == JsonToken.VALUE_NULL) {
throw new IOException("Unable to parse token as NUMBER_INT is null line:" + mJp.getCurrentLocation().getLineNr());
} else {
throw new IOException("Unable to parse token as NUMBER_INT line:" + mJp.getCurrentLocation().getLineNr());
}
}
return mJp.getIntValue();
}
示例12: deserialize
@Override
public Date deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
if (parser.getCurrentToken() == JsonToken.VALUE_NUMBER_INT) {
final Calendar newCalendar = DateUtils.newCalendar();
newCalendar.setTimeInMillis(parser.getLongValue());
return newCalendar.getTime();
}
return _parseDate(parser, context);
}
示例13: deserialize
@SuppressWarnings("unchecked")
@Nullable
public static <T extends WampMessage> T deserialize(JsonFactory jsonFactory,
byte[] json) throws JsonParseException, IOException {
try (JsonParser jp = jsonFactory.createParser(json)) {
if (jp.nextToken() != JsonToken.START_ARRAY) {
throw new IOException("Not a JSON array");
}
if (jp.nextToken() != JsonToken.VALUE_NUMBER_INT) {
throw new IOException("Wrong message format");
}
int code = jp.getValueAsInt();
switch (code) {
case HelloMessage.CODE:
return (T) HelloMessage.deserialize(jp);
case WelcomeMessage.CODE:
return (T) WelcomeMessage.deserialize(jp);
case AbortMessage.CODE:
return (T) AbortMessage.deserialize(jp);
case GoodbyeMessage.CODE:
return (T) GoodbyeMessage.deserialize(jp);
case ErrorMessage.CODE:
return (T) ErrorMessage.deserialize(jp);
case PublishMessage.CODE:
return (T) PublishMessage.deserialize(jp);
case PublishedMessage.CODE:
return (T) PublishedMessage.deserialize(jp);
case SubscribeMessage.CODE:
return (T) SubscribeMessage.deserialize(jp);
case SubscribedMessage.CODE:
return (T) SubscribedMessage.deserialize(jp);
case UnsubscribeMessage.CODE:
return (T) UnsubscribeMessage.deserialize(jp);
case UnsubscribedMessage.CODE:
return (T) UnsubscribedMessage.deserialize(jp);
case EventMessage.CODE:
return (T) EventMessage.deserialize(jp);
case CallMessage.CODE:
return (T) CallMessage.deserialize(jp);
case ResultMessage.CODE:
return (T) ResultMessage.deserialize(jp);
case RegisterMessage.CODE:
return (T) RegisterMessage.deserialize(jp);
case RegisteredMessage.CODE:
return (T) RegisteredMessage.deserialize(jp);
case UnregisterMessage.CODE:
return (T) UnregisterMessage.deserialize(jp);
case UnregisteredMessage.CODE:
return (T) UnregisteredMessage.deserialize(jp);
case YieldMessage.CODE:
return (T) YieldMessage.deserialize(jp);
case InvocationMessage.CODE:
return (T) InvocationMessage.deserialize(jp);
default:
return null;
}
}
}