本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.isDouble方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.isDouble方法的具体用法?Java JsonNode.isDouble怎么用?Java JsonNode.isDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.isDouble方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKvEntries
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static List<KvEntry> getKvEntries(JsonNode data) {
List<KvEntry> attributes = new ArrayList<>();
for (Iterator<Map.Entry<String, JsonNode>> it = data.fields(); it.hasNext();) {
Map.Entry<String, JsonNode> field = it.next();
String key = field.getKey();
JsonNode value = field.getValue();
if (value.isBoolean()) {
attributes.add(new BooleanDataEntry(key, value.asBoolean()));
} else if (value.isLong()) {
attributes.add(new LongDataEntry(key, value.asLong()));
} else if (value.isDouble()) {
attributes.add(new DoubleDataEntry(key, value.asDouble()));
} else {
attributes.add(new StringDataEntry(key, value.asText()));
}
}
return attributes;
}
示例2: getKvEntries
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static List<KvEntry> getKvEntries(JsonNode data) {
List<KvEntry> attributes = new ArrayList<>();
for (Iterator<Map.Entry<String, JsonNode>> it = data.fields(); it.hasNext(); ) {
Map.Entry<String, JsonNode> field = it.next();
String key = field.getKey();
JsonNode value = field.getValue();
if (value.isBoolean()) {
attributes.add(new BooleanDataEntry(key, value.asBoolean()));
} else if (value.isLong()) {
attributes.add(new LongDataEntry(key, value.asLong()));
} else if (value.isDouble()) {
attributes.add(new DoubleDataEntry(key, value.asDouble()));
} else {
attributes.add(new StringDataEntry(key, value.asText()));
}
}
return attributes;
}
示例3: 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;
}
}
示例4: parse
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static <T> Optional<T> parse(String fieldName, JsonNode node, Class<T> type) {
JsonNode field = node.get(fieldName);
T value = null;
if (field != null && !field.isNull()) {
if (type.equals(Long.class) && field.canConvertToLong()) {
value = type.cast(field.asLong());
}
if (type.equals(Integer.class) && field.canConvertToInt()) {
value = type.cast(field.asInt());
}
if (field.isTextual()) {
value = type.cast(field.asText());
}
if (field.isDouble() || type.equals(Double.class)) {
value = type.cast(field.asDouble());
}
if (field.isBoolean()) {
value = type.cast(field.asBoolean());
}
}
return Optional.ofNullable(value);
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: evalObject
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void evalObject(ObjectNode source, ObjectNode target, RenderContext context,
ScriptContext scriptContext)
{
final Iterator<Entry<String, JsonNode>> it = source.fields();
while( it.hasNext() )
{
final Entry<String, JsonNode> e = it.next();
final String name = e.getKey();
final JsonNode n = e.getValue();
if( n.isObject() )
{
// recursively handle it
final ObjectNode nt = jsonMapper.createObjectNode();
target.put(name, nt);
evalObject((ObjectNode) n, nt, context, scriptContext);
}
else if( n.isInt() || n.isLong() )
{
target.put(name, n.asInt());
}
else if( n.isFloatingPointNumber() || n.isDouble() )
{
target.put(name, n.asDouble());
}
else if( n.isBoolean() )
{
target.put(name, n.asBoolean());
}
else if( n.isArray() )
{
target.putArray(name).addAll((ArrayNode) n);
}
else
{
// freemarker eval
target.put(name, evaluateMarkUp(context, n.asText(), scriptContext));
}
}
}
示例9: 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);
}
}
}