本文整理汇总了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);
}
}
}
示例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;
}
示例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;
}
示例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: 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);
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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;
}
示例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 "";
}
}
示例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;
}
示例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;
}
}
示例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;
}