Java Code Examples for com.fasterxml.jackson.databind.JsonNode#isNull()
The following examples show how to use
com.fasterxml.jackson.databind.JsonNode#isNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultProcessLocalizationManager.java From flowable-engine with Apache License 2.0 | 6 votes |
@Override public void localize(ProcessInstance processInstance, String locale, boolean withLocalizationFallback) { ExecutionEntity processInstanceExecution = (ExecutionEntity) processInstance; processInstanceExecution.setLocalizedName(null); processInstanceExecution.setLocalizedDescription(null); if (locale != null) { String processDefinitionId = processInstanceExecution.getProcessDefinitionId(); if (processDefinitionId != null) { ObjectNode languageNode = BpmnOverrideContext.getLocalizationElementProperties(locale, processInstanceExecution.getProcessDefinitionKey(), processDefinitionId, withLocalizationFallback); if (languageNode != null) { JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME); if (languageNameNode != null && !languageNameNode.isNull()) { processInstanceExecution.setLocalizedName(languageNameNode.asText()); } JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION); if (languageDescriptionNode != null && !languageDescriptionNode.isNull()) { processInstanceExecution.setLocalizedDescription(languageDescriptionNode.asText()); } } } } }
Example 2
Source File: PubsubMessageToObjectNode.java From gcp-ingestion with Mozilla Public License 2.0 | 6 votes |
/** * This method gives us a chance to perform some additional type coercions in case the BigQuery * field type is different from the source data type. This should rarely happen, since only * validated payloads get through to this BQ sink path, but there are sets of probes with * heterogeneous types that appear as explicit fields in BQ, but are treated as loosely typed * maps at the validation phase; we need to catch these or they can cause the entire pipeline * to stall. * * <p>Returning {@link Optional#empty} here indicates that no coercion is defined and that the * field should be put to {@code additional_properties}. */ private Optional<JsonNode> coerceToBqType(JsonNode o, Field field) { if (o.isNull()) { // null is valid for any type, just not as an element of a list return Optional.of(o); } else if (field.getMode() == Field.Mode.REPEATED) { if (o.isArray()) { // We have not yet observed a case where an array type contains values that cannot be // coerced to appropriate values, but if it does this will throw NoSuchElementException // and prevent the message from being delivered to BigQuery in a form that could lead to // data being missed in additional_properties. return Optional.of(Json.createArrayNode() .addAll(Streams.stream(o).map(v -> coerceSingleValueToBqType(v, field)) .map(Optional::get).collect(Collectors.toList()))); } else { return Optional.empty(); } } else { return coerceSingleValueToBqType(o, field); } }
Example 3
Source File: MahutaCustomRepositoryImpl.java From Mahuta with Apache License 2.0 | 6 votes |
/** * Deserialize a JSONNode to a primitive object * * @param node JSON node * @return primitive object */ public static Object deserialize(JsonNode node) { if (node == null || node.isMissingNode() || node.isNull()) { return ""; // Because toMap doesn't accept null value ... } else if (node.isBoolean()) { return node.asBoolean(); } else if (node.isLong()) { return node.asLong(); } else if (node.isInt()) { return node.asInt(); } else if (node.isDouble()) { return node.asDouble(); } else if (node.isArray()) { return StreamSupport .stream(Spliterators.spliteratorUnknownSize(node.elements(), Spliterator.ORDERED), false) .map(MahutaCustomRepositoryImpl::deserialize).collect(Collectors.toList()); } else { return node.asText(); } }
Example 4
Source File: EntityUpdateJsonTraverser.java From agrest with Apache License 2.0 | 6 votes |
private void processRelationship(EntityUpdateJsonVisitor visitor, AgRelationship relationship, JsonNode valueNode) { if (valueNode.isArray()) { ArrayNode arrayNode = (ArrayNode) valueNode; if (arrayNode.size() == 0) { // this is kind of a a hack/workaround addRelatedObject(visitor, relationship, null); } else { for (int i = 0; i < arrayNode.size(); i++) { addRelatedObject(visitor, relationship, converter(relationship).value(arrayNode.get(i))); } } } else { if (relationship.isToMany() && valueNode.isNull()) { LOGGER.warn("Unexpected 'null' for a to-many relationship: {}. Skipping...", relationship.getName()); } else { addRelatedObject(visitor, relationship, converter(relationship).value(valueNode)); } } }
Example 5
Source File: BpmnJsonConverter.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
private void filterAllEdges(JsonNode objectNode, Map<String, JsonNode> edgeMap, Map<String, List<JsonNode>> sourceAndTargetMap, Map<String, JsonNode> shapeMap, Map<String, JsonNode> sourceRefMap) { if (objectNode.get(EDITOR_CHILD_SHAPES) != null) { for (JsonNode jsonChildNode : objectNode.get(EDITOR_CHILD_SHAPES)) { ObjectNode childNode = (ObjectNode) jsonChildNode; String stencilId = BpmnJsonConverterUtil.getStencilId(childNode); if (STENCIL_SUB_PROCESS.equals(stencilId) || STENCIL_POOL.equals(stencilId) || STENCIL_LANE.equals(stencilId)) { filterAllEdges(childNode, edgeMap, sourceAndTargetMap, shapeMap, sourceRefMap); } else if (STENCIL_SEQUENCE_FLOW.equals(stencilId) || STENCIL_ASSOCIATION.equals(stencilId)) { String childEdgeId = BpmnJsonConverterUtil.getElementId(childNode); JsonNode targetNode = childNode.get("target"); if (targetNode != null && targetNode.isNull() == false) { String targetRefId = targetNode.get(EDITOR_SHAPE_ID).asText(); List<JsonNode> sourceAndTargetList = new ArrayList<JsonNode>(); sourceAndTargetList.add(sourceRefMap.get(childNode.get(EDITOR_SHAPE_ID).asText())); sourceAndTargetList.add(shapeMap.get(targetRefId)); sourceAndTargetMap.put(childEdgeId, sourceAndTargetList); } edgeMap.put(childEdgeId, childNode); } } } }
Example 6
Source File: HistogramStateIoProvider.java From constellation with Apache License 2.0 | 5 votes |
@Override public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, ImmutableObjectCache cache) throws IOException { if (!jnode.isNull()) { final HistogramState state = new HistogramState(); state.setElementType(GraphElementType.valueOf(jnode.get("elementType").asText())); state.setAttributeType(AttributeType.valueOf(jnode.get("attributeType").asText())); state.setAttribute(jnode.get("attribute").asText()); state.setBinComparator(BinComparator.valueOf(jnode.get("binComparator").asText())); final JsonNode binFormatterNode = jnode.get("binFormatter"); if (binFormatterNode == null) { state.setBinFormatter(BinFormatter.DEFAULT_BIN_FORMATTER); } else { state.setBinFormatter(BinFormatter.getBinFormatter(binFormatterNode.asText())); PluginParameters parameters = state.getBinFormatter().createParameters(); state.getBinFormatter().updateParameters(parameters); if (parameters != null) { JsonNode binFormatterParametersNode = jnode.get("binFormatterParameters"); if (binFormatterParametersNode != null) { for (PluginParameter<?> parameter : parameters.getParameters().values()) { JsonNode valueNode = binFormatterParametersNode.get(parameter.getId()); if (valueNode != null) { parameter.setStringValue(valueNode.asText()); } } } } state.setBinFormatterParameters(parameters); } state.setBinSelectionMode(BinSelectionMode.valueOf(jnode.get("binSelectionMode").asText())); graph.setObjectValue(attributeId, elementId, state); } }
Example 7
Source File: ThingDeserializer.java From ure with MIT License | 5 votes |
@Override public UThing deserialize(JsonParser parser, DeserializationContext context) throws IOException { ObjectCodec codec = parser.getCodec(); JsonNode node = codec.readTree(parser); JsonNode typeNode = node.get("type"); String type = (typeNode != null && !typeNode.isNull()) ? node.get("type").asText() : null; Class<? extends UThing> thingClass = classForType(type); UThing t = objectMapper.treeToValue(node, thingClass); return t; }
Example 8
Source File: SkipExpressionUtil.java From flowable-engine with Apache License 2.0 | 5 votes |
protected static boolean isEnableSkipExpression(ObjectNode globalProperties) { if (globalProperties != null) { JsonNode overrideValueNode = globalProperties.get(DynamicBpmnConstants.ENABLE_SKIP_EXPRESSION); if (overrideValueNode != null && !overrideValueNode.isNull() && "true".equalsIgnoreCase(overrideValueNode.asText())) { return true; } } return false; }
Example 9
Source File: Service.java From hypergraphql with Apache License 2.0 | 5 votes |
Map<String, Set<String>> getResultset(Model model, JsonNode query, Set<String> input, Set<String> markers, HGQLSchema schema) { Map<String, Set<String>> resultset = new HashMap<>(); JsonNode node; if (query.isArray()) { node = query; // TODO - in this situation, we should iterate over the array } else { node = query.get("fields"); if (markers.contains(query.get("nodeId").asText())){ resultset.put(query.get("nodeId").asText(),findRootIdentifiers(model,schema.getTypes().get(query.get("targetName").asText()))); } } Set<LinkedList<QueryNode>> paths = new HashSet<>(); if (node != null && !node.isNull()) { paths = getQueryPaths(node, schema); } paths.forEach(path -> { if (hasMarkerLeaf(path, markers)) { Set<String> identifiers = findIdentifiers(model, input, path); String marker = getLeafMarker(path); resultset.put(marker, identifiers); } }); // TODO query happens to be an array sometimes - then the following line fails. return resultset; }
Example 10
Source File: JsonNodeClaim.java From java-jwt with MIT License | 5 votes |
/** * Helper method to create a Claim representation from the given JsonNode. * * @param node the JsonNode to convert into a Claim. * @return a valid Claim instance. If the node is null or missing, a NullClaim will be returned. */ static Claim claimFromNode(JsonNode node, ObjectReader objectReader) { if (node == null || node.isNull() || node.isMissingNode()) { return new NullClaim(); } return new JsonNodeClaim(node, objectReader); }
Example 11
Source File: ElasticsearchClient.java From presto with Apache License 2.0 | 5 votes |
private JsonNode nullSafeNode(JsonNode jsonNode, String name) { if (jsonNode == null || jsonNode.isNull() || jsonNode.get(name) == null) { return NullNode.getInstance(); } return jsonNode.get(name); }
Example 12
Source File: ODataJsonDeserializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private ComplexValue readComplexValue(final String name, final EdmType type, final boolean isNullable, final JsonNode jsonNode) throws DeserializerException { if (isValidNull(name, isNullable, jsonNode)) { return null; } if (jsonNode.isArray() || !jsonNode.isContainerNode()) { throw new DeserializerException( "Invalid value for property: " + name + " must not be an array or primitive value.", DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, name); } // Even if there are no properties defined we have to give back an empty list ComplexValue complexValue = new ComplexValue(); EdmComplexType edmType = (EdmComplexType) type; //Check if the properties are from derived type edmType = (EdmComplexType) getDerivedType(edmType, jsonNode); // Check and consume all Properties for (String propertyName : edmType.getPropertyNames()) { JsonNode subNode = jsonNode.get(propertyName); if (subNode != null) { EdmProperty edmProperty = (EdmProperty) edmType.getProperty(propertyName); if (subNode.isNull() && !edmProperty.isNullable()) { throw new DeserializerException("Property: " + propertyName + " must not be null.", DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, propertyName); } Property property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(), edmProperty.isCollection(), edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.getMapping(), subNode); complexValue.getValue().add(property); ((ObjectNode) jsonNode).remove(propertyName); } } complexValue.setTypeName(edmType.getFullQualifiedName().getFullQualifiedNameAsString()); return complexValue; }
Example 13
Source File: GetRuntimeFormDefinitionCmd.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void fillVariablesWithFormValues(Map<String, JsonNode> submittedFormFieldMap, List<FormField> allFields) { for (FormField field : allFields) { JsonNode fieldValueNode = submittedFormFieldMap.get(field.getId()); if (fieldValueNode == null || fieldValueNode.isNull()) { continue; } String fieldType = field.getType(); String fieldValue = fieldValueNode.asText(); if (FormFieldTypes.DATE.equals(fieldType)) { try { if (StringUtils.isNotEmpty(fieldValue)) { LocalDate dateValue = LocalDate.parse(fieldValue); variables.put(field.getId(), dateValue); } } catch (Exception e) { logger.error("Error parsing form date value for process instance " + processInstanceId + " with value " + fieldValue, e); } } else { variables.put(field.getId(), fieldValue); } } }
Example 14
Source File: LandscaperDeserializer.java From ure with MIT License | 5 votes |
@Override public ULandscaper deserialize(JsonParser parser, DeserializationContext context) throws IOException { ObjectCodec codec = parser.getCodec(); JsonNode node = codec.readTree(parser); JsonNode typeNode = node.get("type"); String type = (typeNode != null && !typeNode.isNull()) ? node.get("type").asText() : null; Class<? extends ULandscaper> landscaperClass = classForType(type); return objectMapper.treeToValue(node, landscaperClass); }
Example 15
Source File: LocalMaterializationSystemBuilder.java From tasmo with Apache License 2.0 | 5 votes |
private String getViewClassFromViewModel(ObjectNode viewNode) { for (Iterator<String> it = viewNode.fieldNames(); it.hasNext();) { String fieldName = it.next(); JsonNode got = viewNode.get(fieldName); if (got != null && !got.isNull() && got.isObject() && got.has(ReservedFields.VIEW_OBJECT_ID)) { return fieldName; } } return ""; }
Example 16
Source File: HyperlinkIOProvider.java From constellation with Apache License 2.0 | 5 votes |
@Override public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, final ImmutableObjectCache cache) throws IOException { final String attributeValue = jnode.isNull() ? null : jnode.textValue(); graph.setStringValue(attributeId, elementId, attributeValue); }
Example 17
Source File: BpmnJsonConverterUtil.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
protected static void parseListeners(JsonNode listenersNode, BaseElement element, boolean isTaskListener) { if (listenersNode == null) return; listenersNode = validateIfNodeIsTextual(listenersNode); for (JsonNode listenerNode : listenersNode) { listenerNode = validateIfNodeIsTextual(listenerNode); JsonNode eventNode = listenerNode.get(PROPERTY_LISTENER_EVENT); if (eventNode != null && eventNode.isNull() == false && StringUtils.isNotEmpty(eventNode.asText())) { ActivitiListener listener = new ActivitiListener(); listener.setEvent(eventNode.asText()); if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_CLASS_NAME, listenerNode))) { listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS); listener.setImplementation(getValueAsString(PROPERTY_LISTENER_CLASS_NAME, listenerNode)); } else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_EXPRESSION, listenerNode))) { listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION); listener.setImplementation(getValueAsString(PROPERTY_LISTENER_EXPRESSION, listenerNode)); } else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listenerNode))) { listener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); listener.setImplementation(getValueAsString(PROPERTY_LISTENER_DELEGATE_EXPRESSION, listenerNode)); } JsonNode fieldsNode = listenerNode.get(PROPERTY_LISTENER_FIELDS); if (fieldsNode != null) { for (JsonNode fieldNode : fieldsNode) { JsonNode nameNode = fieldNode.get(PROPERTY_FIELD_NAME); if (nameNode != null && nameNode.isNull() == false && StringUtils.isNotEmpty(nameNode.asText())) { FieldExtension fieldExtension = new FieldExtension(); fieldExtension.setFieldName(nameNode.asText()); fieldExtension.setStringValue(getValueAsString(PROPERTY_FIELD_STRING_VALUE, fieldNode)); if (StringUtils.isEmpty(fieldExtension.getStringValue())) { fieldExtension.setStringValue(getValueAsString(PROPERTY_FIELD_STRING, fieldNode)); } if (StringUtils.isEmpty(fieldExtension.getStringValue())) { fieldExtension.setExpression(getValueAsString(PROPERTY_FIELD_EXPRESSION, fieldNode)); } listener.getFieldExtensions().add(fieldExtension); } } } if (element instanceof Process) { ((Process) element).getExecutionListeners().add(listener); } else if (element instanceof SequenceFlow) { ((SequenceFlow) element).getExecutionListeners().add(listener); } else if (element instanceof UserTask) { if (isTaskListener) { ((UserTask) element).getTaskListeners().add(listener); } else { ((UserTask) element).getExecutionListeners().add(listener); } } else if (element instanceof FlowElement) { ((FlowElement) element).getExecutionListeners().add(listener); } } } }
Example 18
Source File: ODataJsonDeserializer.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void assertIsNullNode(final String key, final JsonNode jsonNode) throws DeserializerException { if (jsonNode.isNull()) { throw new DeserializerException("Annotation: " + key + "must not have a null value.", DeserializerException.MessageKeys.INVALID_NULL_ANNOTATION, key); } }
Example 19
Source File: BlazeIOProvider.java From constellation with Apache License 2.0 | 4 votes |
@Override public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, ImmutableObjectCache cache) throws IOException { final String attributeValue = jnode.isNull() ? null : jnode.textValue(); graph.setStringValue(attributeId, elementId, attributeValue); }
Example 20
Source File: LispExtensionMappingAddressInterpreter.java From onos with Apache License 2.0 | 2 votes |
/** * Gets a child Object Node from a parent by name. If the child is not found * or does nor represent an object, null is returned. * * @param parent parent object * @param childName name of child to query * @return child object if found, null if not found or if not an object */ private static ObjectNode get(ObjectNode parent, String childName) { JsonNode node = parent.path(childName); return node.isObject() && !node.isNull() ? (ObjectNode) node : null; }