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