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


Java JsonNode.isFloat方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.JsonNode.isFloat方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonNode.isFloat方法的具體用法?Java JsonNode.isFloat怎麽用?Java JsonNode.isFloat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.databind.JsonNode的用法示例。


在下文中一共展示了JsonNode.isFloat方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fromJson

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
@Override
public Number fromJson(JsonNode json) {
	if (json.isBigDecimal()) {
		return json.decimalValue();
	} else if (json.isBigInteger()) {
		return json.bigIntegerValue();
	}
	// no methods for Byte, even though numberNode(Byte) is provided.
	// experimentations shows that bytes show up as ints. Oh well..
	else if (json.isDouble()) {
		return json.doubleValue();
	} else if (json.isFloat()) {
		return json.floatValue();
	} else if (json.isInt()) {
		return json.intValue();
	} else if (json.isLong()) {
		return json.longValue();
	} else if (json.isShort()) {
		return json.shortValue();
	} else {
		return null;
	}
}
 
開發者ID:networknt,項目名稱:openapi-parser,代碼行數:24,代碼來源:NumberOverlay.java

示例2: createSclarProperty

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private Property createSclarProperty(String arrayType, JsonNode node) {
	Property property = null;
	Iterator<JsonNode> nodes = node.elements();
	while (nodes.hasNext()) {
		JsonNode leafNode = nodes.next();
		JsonNodeType type = leafNode.getNodeType();
		switch (type) {
		case STRING:
			property = new StringPropertyBuilder().withExample(leafNode.asText()).build();
			break;
		case BOOLEAN:
			property = new BooleanPropertyBuilder().withExample(leafNode.asBoolean()).build();
			break;
		case NUMBER:
			if (leafNode.isInt() || leafNode.isLong()) {
				property = new IntegerPropertyBuilder().withExample(leafNode.asLong()).build();
			} else if (leafNode.isFloat() || leafNode.isDouble()) {
				property = new NumberPropertyBuilder().withExample(leafNode.asDouble()).build();
			}
			break;
		default:
			break;
		}
	}
	return property;
}
 
開發者ID:pegasystems,項目名稱:api2swagger,代碼行數:27,代碼來源:SwaggerModelGenerator.java

示例3: identifyPrimitiveMatch

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private static UnionResolution identifyPrimitiveMatch(JsonNode datum, Set<Schema.Type> primitives) {
  // Try to identify specific primitive types
  Schema primitiveSchema = null;
  if (datum == null || datum.isNull()) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.NULL);
  } else if (datum.isShort() || datum.isInt()) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.INT, Schema.Type.LONG, Schema.Type.FLOAT,
        Schema.Type.DOUBLE);
  } else if (datum.isLong()) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.LONG, Schema.Type.DOUBLE);
  } else if (datum.isFloat()) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.FLOAT, Schema.Type.DOUBLE);
  } else if (datum.isDouble()) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.DOUBLE);
  } else if (datum.isBoolean()) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.BOOLEAN);
  }
  if (primitiveSchema == null
      && ((datum.isDouble() && datum.doubleValue() >= -Float.MAX_VALUE && datum.doubleValue() <= Float.MAX_VALUE)
          || (datum.isLong()
              && datum.longValue() >= (long) -Float.MAX_VALUE
              && datum.longValue() <= (long) Float.MAX_VALUE))) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.FLOAT, Schema.Type.DOUBLE);
  }

  if (primitiveSchema != null) {
    return new UnionResolution(primitiveSchema, MatchType.FULL);
  }
  return null;
}
 
開發者ID:HotelsDotCom,項目名稱:jasvorno,代碼行數:31,代碼來源:JasvornoConverter.java

示例4: matches

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private MatchType matches(JsonNode datum, Schema schema) {
  switch (schema.getType()) {
  case RECORD:
    if (datum.isObject()) {
      return matchRecord(datum, schema);
    }
    break;
  case UNION:
    return resolveUnion(datum, schema.getTypes()).matchType;
  case MAP:
    if (datum.isObject()) {
      return matchMapValue(datum, schema);
    }
    break;
  case ARRAY:
    if (datum.isArray()) {
      return matchArrayElement(datum, schema);
    }
    break;
  case BOOLEAN:
    if (datum.isBoolean()) {
      return MatchType.FULL;
    }
    break;
  case FLOAT:
    if (datum.isDouble() && datum.doubleValue() >= -Float.MAX_VALUE && datum.doubleValue() <= Float.MAX_VALUE
        || datum.isLong()
            && datum.longValue() >= (long) -Float.MAX_VALUE
            && datum.longValue() <= (long) Float.MAX_VALUE
        || datum.isFloat()
        || datum.isInt()) {
      return MatchType.FULL;
    }
    break;
  case DOUBLE:
    if (datum.isDouble() || datum.isFloat() || datum.isLong() || datum.isInt()) {
      return MatchType.FULL;
    }
    break;
  case INT:
    if (datum.isInt()) {
      return MatchType.FULL;
    }
    break;
  case LONG:
    if (datum.isLong() || datum.isInt()) {
      return MatchType.FULL;
    }
    break;
  case STRING:
    if (datum.isTextual()) {
      return MatchType.FULL;
    }
    break;
  case ENUM:
    if (datum.isTextual() && schema.hasEnumSymbol(datum.textValue())) {
      return MatchType.FULL;
    }
    break;
  case BYTES:
  case FIXED:
    if (datum.isTextual()) {
      return MatchType.FULL;
    }
    break;
  case NULL:
    if (datum.isNull()) {
      return MatchType.FULL;
    }
    break;
  default: // unknown
    throw new IllegalArgumentException("Unsupported schema: " + schema);
  }
  return MatchType.NONE;
}
 
開發者ID:HotelsDotCom,項目名稱:jasvorno,代碼行數:76,代碼來源:JasvornoConverter.java

示例5: createObjectModel

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private void createObjectModel(JsonNode node, ModelBuilder modelBuilder, String apiName) {
	Iterator<String> fieldNames = node.fieldNames();

	while (fieldNames.hasNext()) {
		String field = fieldNames.next();
		JsonNode leafNode = node.get(field);

		if (leafNode.getNodeType() == JsonNodeType.NUMBER) {
			if (leafNode.isInt() || leafNode.isLong()) {
				modelBuilder.withIntegerPropertyNamed(field).withExample(leafNode.asLong());
			} else if (leafNode.isFloat() || leafNode.isDouble()) {
				modelBuilder.withNumberPropertyNamed(field).withExample(leafNode.asDouble());
			}
		} else if (leafNode.getNodeType() == JsonNodeType.BOOLEAN) {
			modelBuilder.withBooleanPropertyNamed(field).withExample(leafNode.asBoolean());
		} else if (leafNode.getNodeType() == JsonNodeType.STRING) {
			modelBuilder.withStringPropertyNamed(field).withExample(leafNode.asText());
		} else if (leafNode.getNodeType() == JsonNodeType.OBJECT) {
			String refName = apiName+"-"+field;
			modelBuilder.withReferencePropertyNamed(field).withReferenceTo(refName);
			ModelBuilder objModelBuilder = new ModelBuilder();
			createObjectModel(leafNode, objModelBuilder, refName);
			models.put(refName, objModelBuilder);
		}else if(leafNode.getNodeType() == JsonNodeType.ARRAY){
			createArrayModel(leafNode, modelBuilder.withArrayProperty(field), apiName+"-"+field);				
		}
	}		
}
 
開發者ID:pegasystems,項目名稱:api2swagger,代碼行數:29,代碼來源:SwaggerModelGenerator.java


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