本文整理汇总了Java中com.fasterxml.jackson.core.JsonParser.getDoubleValue方法的典型用法代码示例。如果您正苦于以下问题:Java JsonParser.getDoubleValue方法的具体用法?Java JsonParser.getDoubleValue怎么用?Java JsonParser.getDoubleValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.core.JsonParser
的用法示例。
在下文中一共展示了JsonParser.getDoubleValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
@Override
public Object parse(JsonParser jsonParser) throws IOException {
switch (jsonParser.getCurrentToken()) {
case VALUE_NULL:
return null;
case VALUE_FALSE:
return false;
case VALUE_TRUE:
return true;
case VALUE_NUMBER_FLOAT:
return jsonParser.getDoubleValue();
case VALUE_NUMBER_INT:
return jsonParser.getLongValue();
case VALUE_STRING:
return jsonParser.getText();
case VALUE_EMBEDDED_OBJECT:
return LoganSquare.mapperFor(Map.class).parse(jsonParser);
case START_OBJECT:
return LoganSquare.mapperFor(Map.class).parse(jsonParser);
case START_ARRAY:
return LoganSquare.mapperFor(List.class).parse(jsonParser);
default:
throw new RuntimeException("Invalid json token encountered: " + jsonParser.getCurrentToken());
}
}
示例2: parse
import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
@Override
public Double parse(JsonParser jsonParser) throws IOException {
if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL) {
return null;
} else {
return jsonParser.getDoubleValue();
}
}
示例3: 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;
}
}
示例4: loadPart
import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
private static Part loadPart(int index, JsonParser parser, double location) throws IOException {
if (parser.nextToken() != JsonToken.FIELD_NAME) {
throw new IOException( "Field name expected.");
}
if (!Objects.equals(parser.getCurrentName(), "length")) {
throw new IOException("length field expected.");
}
parser.nextToken();
double length = parser.getDoubleValue();
if (parser.nextToken() != JsonToken.FIELD_NAME) {
throw new IOException("Field name expected.");
}
if (!Objects.equals(parser.getCurrentName(), "type")) {
throw new IOException("type field expected.");
}
parser.nextToken();
String val = parser.getText();
Part.TYPE type;
if (Objects.equals(val, "s")) {
type = Part.TYPE.STRAIGHT;
} else if (Objects.equals(val, "c")) {
type = Part.TYPE.CURVED;
} else {
throw new IOException("Invalid part type detected.");
}
if (parser.nextToken() != JsonToken.END_OBJECT) {
throw new IOException("Expected object to end.");
}
return new Part(index, type, length, location);
}
示例5: deserialize
import com.fasterxml.jackson.core.JsonParser; //导入方法依赖的package包/类
@Override
public AttributeValueDto deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
JsonToken currentToken = jp.getCurrentToken();
if (currentToken != null) {
switch (currentToken) {
case VALUE_NUMBER_INT:
case VALUE_NUMBER_FLOAT:
return new DoubleAttributeValueDto(jp.getDoubleValue());
case VALUE_STRING:
return new StringAttributeValueDto(jp.getText());
case VALUE_TRUE:
return new BooleanAttributeValueDto(jp.getBooleanValue());
case VALUE_FALSE:
return new BooleanAttributeValueDto(jp.getBooleanValue());
case START_ARRAY: {
ArrayAttributeValueDto arrayValue = null;
ObjectMapper mapper = new ObjectMapper();
ArrayNode arrayNode = mapper.readTree(jp);
Iterator<JsonNode> it = arrayNode.elements();
JsonNodeType arrayElemType = null;
while (it.hasNext()) {
JsonNode node = it.next();
if (arrayValue == null) {
// get the first element type
arrayElemType = node.getNodeType();
switch (arrayElemType) {
case STRING:
arrayValue = new ArrayOfStringsAttributeValueDto();
break;
case NUMBER:
arrayValue = new ArrayOfDoublesAttributeValueDto();
break;
default:
throw new UnsupportedOperationException(
"Unsupported array attribute items type.");
}
} else if (arrayElemType != node.getNodeType()) {
String errString = String.format(
"Array doesn't support different element types!Expected:{}, Found:{} ",
arrayElemType, node.getNodeType());
LOGGER.warn(errString);
throw new UnsupportedOperationException(errString);
}
switch (arrayElemType) {
case STRING:
((ArrayOfStringsAttributeValueDto) arrayValue).add(node.asText());
break;
case NUMBER:
((ArrayOfDoublesAttributeValueDto) arrayValue).add(node.asDouble());
break;
default:
break;
}
}
return arrayValue;
}
default:
break;
}
}
throw new UnsupportedOperationException("Not supported attribute value yet.");
}