本文整理匯總了Java中com.fasterxml.jackson.core.JsonParser.getNumberType方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonParser.getNumberType方法的具體用法?Java JsonParser.getNumberType怎麽用?Java JsonParser.getNumberType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.fasterxml.jackson.core.JsonParser
的用法示例。
在下文中一共展示了JsonParser.getNumberType方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processValue
import com.fasterxml.jackson.core.JsonParser; //導入方法依賴的package包/類
/**
* Uses a JsonToken + JsonParser to determine how to write a value to the JsonGenerator.
*
* <p>This separation exists so we can separate the iteration logic from the parsing logic.
*
* @param valueToken current token we are interested in from the parser
* @param parser current parser
* @param jgen JsonGenerator that is used for writing json onto an underlying stream
* @throws JsonGenerationException if access to the JsonParser throws a JsonGenerationException
* @throws IOException if the Jackson utilties (JsonParser or JsonGenerator) throw an IOException
*/
private void processValue(JsonToken valueToken, JsonParser parser, JsonGenerator jgen)
throws IOException {
if (valueToken.isBoolean()) {
jgen.writeBoolean(parser.getBooleanValue());
} else if (valueToken.isNumeric()) {
if (parser.getNumberType() == JsonParser.NumberType.INT) {
jgen.writeNumber(parser.getIntValue());
} else if (parser.getNumberType() == JsonParser.NumberType.DOUBLE) {
jgen.writeNumber(parser.getDoubleValue());
} else if (parser.getNumberType() == JsonParser.NumberType.FLOAT) {
jgen.writeNumber(parser.getFloatValue());
} else if (parser.getNumberType() == JsonParser.NumberType.LONG) {
jgen.writeNumber(parser.getLongValue());
} else if (parser.getNumberType() == JsonParser.NumberType.BIG_DECIMAL) {
jgen.writeNumber(parser.getDecimalValue());
} else if (parser.getNumberType() == JsonParser.NumberType.BIG_INTEGER) {
jgen.writeNumber(parser.getBigIntegerValue());
} else {
LOGGER.error("Found unsupported numeric value with name {}.", parser.getCurrentName());
throw new RuntimeException(
"Found unsupported numeric value with name " + parser.getCurrentName());
}
} else if (valueToken.id() == JsonTokenId.ID_STRING) {
jgen.writeString(parser.getText());
} else {
// Something bad just happened. Probably an unsupported type.
LOGGER.error(
"Found unsupported value type {} for name {}.", valueToken.id(), parser.getCurrentName());
throw new RuntimeException(
"Found unsupported value type " + valueToken.id() + " for name " + parser
.getCurrentName());
}
}
示例2: 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;
}
}
示例3: 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;
}
}