本文整理汇总了Java中com.fasterxml.jackson.core.JsonParser.getTextLength方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParser.getTextLength方法的具体用法?Java JsonParser.getTextLength怎么用?Java JsonParser.getTextLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.core.JsonParser
的用法示例。
在下文中一共展示了JsonParser.getTextLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: parseDouble
import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
/** Parsers a double value out of the input. */
static double parseDouble(JsonParser parser) throws IOException {
JsonToken current = parser.currentToken();
if (!current.isNumeric()) {
String json = parser.getText();
if (json.equals("NaN")) {
return Double.NaN;
} else if (json.equals("Infinity")) {
return Double.POSITIVE_INFINITY;
} else if (json.equals("-Infinity")) {
return Double.NEGATIVE_INFINITY;
}
}
try {
// We don't use Double.parseDouble() here because that function simply
// accepts all values. Here we readValue the value into a BigDecimal and do
// explicit range check on it.
BigDecimal value =
new BigDecimal(
parser.getTextCharacters(), parser.getTextOffset(), parser.getTextLength());
if (value.compareTo(MAX_DOUBLE) > 0 || value.compareTo(MIN_DOUBLE) < 0) {
throw new InvalidProtocolBufferException("Out of range double value: " + parser.getText());
}
return value.doubleValue();
} catch (NumberFormatException e) {
throw new InvalidProtocolBufferException("Not an double value: " + parser.getText());
}
}