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


Java JsonNode.isNull方法代碼示例

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


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

示例1: getMemberValue

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * Get the value of the member as specified in the test description. Only supports simple types
 * at the moment.
 *
 * @param currentNode JsonNode containing value of member.
 */
private Object getMemberValue(JsonNode currentNode, MemberModel memberModel) {
    // Streaming members are not in the POJO
    if (currentNode.isNull()) {
        return null;
    }
    if (memberModel.isSimple()) {
        return getSimpleMemberValue(currentNode, memberModel);
    } else if (memberModel.isList()) {
        return getListMemberValue(currentNode, memberModel);
    } else if (memberModel.isMap()) {
        return getMapMemberValue(currentNode, memberModel);
    } else {
        ShapeModel structureShape = model.getShapes()
                                         .get(memberModel.getVariable().getVariableType());
        try {
            return createStructure(structureShape, currentNode);
        } catch (Exception e) {
            throw new TestCaseReflectionException(e);
        }
    }
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:28,代碼來源:ShapeModelReflector.java

示例2: getAsBoolean

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * Geef node waarde als Boolean.
 * @param parentNode parent node
 * @param nodeName naam van de node
 * @param checkValue waarde waarmee gecontroleerd wordt (mag niet null zijn)
 * @param checkBoolean resultaat als de waarde van de node gelijk is aan 'checkValue' (mag null zijn)
 * @param elseBoolean resultaat als de waarde van de node niet gelijk is aan 'checkValue' (mag null zijn)
 * @return checkBoolean of elseBoolean (kan dus null zijn), naar gelang de waarde van de node en checkValue
 */
static Boolean getAsBoolean(
        final JsonNode parentNode,
        final String nodeName,
        final String checkValue,
        final Boolean checkBoolean,
        final Boolean elseBoolean) {
    final Boolean result;
    final JsonNode theNode = parentNode.get(nodeName);
    if (theNode != null && !theNode.isNull() && checkValue.equals(theNode.asText())) {
        result = checkBoolean;
    } else {
        result = elseBoolean;
    }
    return result;
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:25,代碼來源:JsonUtils.java

示例3: getElement

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * Return the field with name in JSON as a string, a boolean, a number or a node.
 *
 * @param json json
 * @param name node name
 * @return the field
 */
public static Object getElement(final JsonNode json, final String name) {
    if (json != null && name != null) {
        JsonNode node = json;
        for (String nodeName : name.split("\\.")) {
            if (node != null) {
                node = node.get(nodeName);
            }
        }
        if (node != null) {
            if (node.isNumber()) {
                return node.numberValue();
            } else if (node.isBoolean()) {
                return node.booleanValue();
            } else if (node.isTextual()) {
                return node.textValue();
            } else if (node.isNull()) {
                return null;
            } else {
                return node;
            }
        }
    }
    return null;
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:32,代碼來源:JsonHelper.java

示例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);
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:23,代碼來源:SanitizingHelper.java

示例5: deserializeResult

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private static <T> T deserializeResult(
        JsonNode result, Command<T> command) throws JsonProcessingException {

    requireNonNull(command, "command");

    // Convert null node to the real null.
    if (result != null && result.isNull()) {
        result = null;
    }

    final Class<T> resultType = Util.unsafeCast(command.type().resultType());
    if (resultType == Void.class) {
        if (result != null) {
            rejectIncompatibleResult(result, Void.class);
        }

        return null;
    }

    return Jackson.treeToValue(result, resultType);
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:22,代碼來源:ReplicationLog.java

示例6: isValid

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * Indicates whether a field in the node is present and of correct value or
 * not mandatory and absent.
 *
 * @param objectNode JSON object node containing field to validate
 * @param field name of field to validate
 * @param presence specified if field is optional or mandatory
 * @param validationFunction function which can be used to verify if the
 *                           node has the correct value
 * @return true if the field is as expected
 * @throws InvalidFieldException if the field is present but not valid
 */
private boolean isValid(ObjectNode objectNode, String field, FieldPresence presence,
                        Function<JsonNode, Boolean> validationFunction) {
    JsonNode node = objectNode.path(field);
    boolean isMandatory = presence == FieldPresence.MANDATORY;
    if (isMandatory && node.isMissingNode()) {
        throw new InvalidFieldException(field, "Mandatory field not present");
    }

    if (!isMandatory && (node.isNull() || node.isMissingNode())) {
        return true;
    }

    try {
        if (validationFunction.apply(node)) {
            return true;
        } else {
            throw new InvalidFieldException(field, "Validation error");
        }
    } catch (IllegalArgumentException e) {
        throw new InvalidFieldException(field, e);
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:35,代碼來源:Config.java

示例7: getDateFromSeconds

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
Date getDateFromSeconds(Map<String, JsonNode> tree, String claimName) {
    JsonNode node = tree.get(claimName);
    if (node == null || node.isNull() || !node.canConvertToLong()) {
        return null;
    }
    final long ms = node.asLong() * 1000;
    return new Date(ms);
}
 
開發者ID:GJWT,項目名稱:javaOIDCMsg,代碼行數:9,代碼來源:PayloadDeserializer.java

示例8: updateDatasetCaseSensitivity

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
public static void updateDatasetCaseSensitivity(JsonNode root)
    throws Exception {
  final JsonNode properties = root.path("datasetProperties");
  if (properties.isMissingNode() || properties.isNull()) {
    throw new IllegalArgumentException(
        "Dataset properties update fail, missing necessary fields: " + root.toString());
  }
  final JsonNode caseSensitivity = properties.path("caseSensitivity");
  if (caseSensitivity.isMissingNode() || caseSensitivity.isNull()) {
    throw new IllegalArgumentException(
        "Dataset properties update fail, missing necessary fields: " + root.toString());
  }

  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
  }
  final Integer datasetId = (Integer) idUrn[0];
  final String urn = (String) idUrn[1];

  ObjectMapper om = new ObjectMapper();

  DatasetCaseSensitiveRecord record = om.convertValue(caseSensitivity, DatasetCaseSensitiveRecord.class);
  record.setDatasetId(datasetId);
  record.setDatasetUrn(urn);
  record.setModifiedTime(System.currentTimeMillis() / 1000);
  try {
    DatasetCaseSensitiveRecord result = getDatasetCaseSensitivityByDatasetId(datasetId);
    String[] columns = record.getDbColumnNames();
    Object[] columnValues = record.getAllValuesToString();
    String[] conditions = {"dataset_id"};
    Object[] conditionValues = new Object[]{datasetId};
    CASE_SENSITIVE_WRITER.update(columns, columnValues, conditions, conditionValues);
  } catch (EmptyResultDataAccessException ex) {
    CASE_SENSITIVE_WRITER.append(record);
    CASE_SENSITIVE_WRITER.insert();
  }
}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:39,代碼來源:DatasetInfoDao.java

示例9: updateDatasetSecurity

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
public static void updateDatasetSecurity(JsonNode root)
    throws Exception {
  final JsonNode security = root.path("securitySpecification");
  if (security.isMissingNode() || security.isNull()) {
    throw new IllegalArgumentException(
        "Dataset security info update fail, missing necessary fields: " + root.toString());
  }

  final Object[] idUrn = findDataset(root);
  if (idUrn[0] == null || idUrn[1] == null) {
    throw new IllegalArgumentException("Cannot identify dataset from id/uri/urn: " + root.toString());
  }
  final Integer datasetId = (Integer) idUrn[0];
  final String urn = (String) idUrn[1];

  ObjectMapper om = new ObjectMapper();

  DatasetSecurityRecord record = om.convertValue(security, DatasetSecurityRecord.class);
  record.setDatasetId(datasetId);
  record.setDatasetUrn(urn);
  record.setModifiedTime(System.currentTimeMillis() / 1000);
  try {
    DatasetSecurityRecord result = getDatasetSecurityByDatasetId(datasetId);
    String[] columns = record.getDbColumnNames();
    Object[] columnValues = record.getAllValuesToString();
    String[] conditions = {"dataset_id"};
    Object[] conditionValues = new Object[]{datasetId};
    SECURITY_WRITER.update(columns, columnValues, conditions, conditionValues);
  } catch (EmptyResultDataAccessException ex) {
    SECURITY_WRITER.append(record);
    SECURITY_WRITER.insert();
  }
}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:34,代碼來源:DatasetInfoDao.java

示例10: parseDefaultValue

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private Object parseDefaultValue(Schema schema, Map<String, JsonNode> fieldAnnotations) {
    JsonNode def = fieldAnnotations.get("Default");
    if (def == null || def.isNull()) {
        return null;
    }
    return new JsonReader().getNodeData(schema, def);
}
 
開發者ID:atlascon,項目名稱:travny,代碼行數:8,代碼來源:RecordSchemaParser.java

示例11: 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

示例12: getSubQuery

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private String getSubQuery(JsonNode fieldsJson, String parentType) {

        Set<String> subQueryStrings = new HashSet<>();

        if (schema.getTypes().containsKey(parentType)) {
            subQueryStrings.add("_id");
            subQueryStrings.add("_type");
        }

        if (fieldsJson==null || fieldsJson.isNull()) {
            if (subQueryStrings.isEmpty()) {
                return "";
            } else {
                querySTR(String.join(" ", subQueryStrings));
            }
        }

        else {


            Iterator<JsonNode> fields = ((ArrayNode) fieldsJson).elements();

            fields.forEachRemaining(field -> {
                ArrayNode fieldsArray = (field.get("fields").isNull()) ? null : (ArrayNode) field.get("fields");
                String arg = (field.get("args").isNull()) ? "" : langSTR((ObjectNode) field.get("args"));
                String fieldString = field.get("name").asText() + arg + " " + getSubQuery(fieldsArray, field.get("targetName").asText());
                subQueryStrings.add(fieldString);
            });
        }

        if (!subQueryStrings.isEmpty()) {
            return querySTR(String.join(" ", subQueryStrings));
        } else {
            return "";
        }
    }
 
開發者ID:semantic-integration,項目名稱:hypergraphql,代碼行數:37,代碼來源:HGraphQLConverter.java

示例13: pathAll

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * PathAll matcher that checks if each element of the final
 * result matches the expected result
 *
 * @param expectedResult Expected result given by the waiter definition
 * @param finalResult    Final result of the resource got by the execution
 *                       of the JmesPath expression given by the waiter
 *                       definition
 * @return True if all elements of the final result matches
 * the expected result, False otherwise
 */
public static boolean pathAll(JsonNode expectedResult, JsonNode finalResult) {
    if (finalResult.isNull()) {
        return false;
    }
    if (!finalResult.isArray()) {
        throw new RuntimeException("Expected an array");
    }
    for (JsonNode element : finalResult) {
        if (!element.equals(expectedResult)) {
            return false;
        }
    }
    return true;
}
 
開發者ID:IBM,項目名稱:ibm-cos-sdk-java,代碼行數:26,代碼來源:AcceptorPathMatcher.java

示例14: getBootStrapHostFromML

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
public static String getBootStrapHostFromML() {
	InputStream jstream=null;
	try{
	DefaultHttpClient client = new DefaultHttpClient();
	client.getCredentialsProvider().setCredentials(
			new AuthScope(host, 8002),
			new UsernamePasswordCredentials("admin", "admin"));
	HttpGet getrequest = new HttpGet("http://"+host+":8002/manage/v2/properties?format=json");
	HttpResponse resp = client.execute(getrequest);
	jstream =resp.getEntity().getContent();
	JsonNode jnode= new ObjectMapper().readTree(jstream);
	String propName ="bootstrap-host";
	if(!jnode.isNull()){

		if(jnode.has(propName)){
		System.out.println("Bootstrap Host: " + jnode.withArray(propName).get(0).get("bootstrap-host-name").asText());
		return jnode.withArray(propName).get(0).get("bootstrap-host-name").asText();
		}
		else{
			System.out.println("Missing "+propName+" field from properties end point so sending java conanical host name\n"+jnode.toString());
			return InetAddress.getLocalHost().getCanonicalHostName().toLowerCase();
			}
		}
	else{
		 System.out.println("Rest endpoint returns empty stream");
		 return InetAddress.getLocalHost().getCanonicalHostName().toLowerCase();
		}

	}catch (Exception e) {
		// writing error to Log
		e.printStackTrace();
		
		return host;
	}
	finally{
		jstream =null;
	}
}
 
開發者ID:marklogic,項目名稱:marklogic-rdf4j,代碼行數:39,代碼來源:ConnectedRESTQA.java

示例15: deserialize

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
@JsonCreator
static DefaultChange<?> deserialize(@JsonProperty("type") ChangeType type,
                                    @JsonProperty("path") String path,
                                    @JsonProperty("content") JsonNode content) {
    requireNonNull(type, "type");
    final Class<?> contentType = type.contentType();
    if (contentType == Void.class) {
        if (content != null && !content.isNull()) {
            return rejectIncompatibleContent(content, Void.class);
        }
    } else if (type.contentType() == String.class) {
        if (content == null || !content.isTextual()) {
            return rejectIncompatibleContent(content, String.class);
        }
    }

    final Change<?> result;

    switch (type) {
        case UPSERT_JSON:
            result = Change.ofJsonUpsert(path, content);
            break;
        case UPSERT_TEXT:
            result = Change.ofTextUpsert(path, content.asText());
            break;
        case REMOVE:
            result = Change.ofRemoval(path);
            break;
        case RENAME:
            result = Change.ofRename(path, content.asText());
            break;
        case APPLY_JSON_PATCH:
            result = Change.ofJsonPatch(path, content);
            break;
        case APPLY_TEXT_PATCH:
            result = Change.ofTextPatch(path, content.asText());
            break;
        default:
            // Should never reach here
            throw new Error();
    }

    // Ugly downcast, but otherwise we would have needed to write a custom serializer.
    return (DefaultChange<?>) result;
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:46,代碼來源:DefaultChange.java


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