當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonParser.getDoubleValue方法代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:ObjectMapper.java

示例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();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:DoubleMapper.java

示例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;
	}
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:35,代碼來源:ParserUtil.java

示例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);
}
 
開發者ID:pushtechnology,項目名稱:racing-demo,代碼行數:35,代碼來源:RaceTrack.java

示例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.");
}
 
開發者ID:Nexmo,項目名稱:comms-router,代碼行數:66,代碼來源:AttributeValueDeserializer.java


注:本文中的com.fasterxml.jackson.core.JsonParser.getDoubleValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。