Java Code Examples for com.fasterxml.jackson.databind.node.ObjectNode#size()

The following examples show how to use com.fasterxml.jackson.databind.node.ObjectNode#size() . 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: ObjectConstructionExpressionEvaluator.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
private JRJsonNode constructNewObjectNodeWithKeys(JRJsonNode from) {
    ObjectNode newNode = getEvaluationContext().getObjectMapper().createObjectNode();

    for (String objectKey: expression.getObjectKeys()) {
        JsonNode deeperNode = from.getDataNode().get(objectKey);

        if (deeperNode != null && (deeperNode.isObject() || deeperNode.isValueNode() || deeperNode.isArray())) {
            JRJsonNode deeperChild = from.createChild(deeperNode);

            if (applyFilter(deeperChild)) {
                newNode.put(objectKey, deeperNode);
            }
        }
    }

    if (newNode.size() > 0) {
        return from.createChild(newNode);
    }

    return null;
}
 
Example 2
Source File: RequestValidator.java    From prebid-server-java with Apache License 2.0 6 votes vote down vote up
private void validateSite(Site site) throws ValidationException {
    if (site != null) {
        if (StringUtils.isBlank(site.getId()) && StringUtils.isBlank(site.getPage())) {
            throw new ValidationException(
                    "request.site should include at least one of request.site.id or request.site.page");
        }

        final ObjectNode siteExt = site.getExt();
        if (siteExt != null && siteExt.size() > 0) {
            try {
                final ExtSite extSite = mapper.mapper().treeToValue(siteExt, ExtSite.class);
                final Integer amp = extSite.getAmp();
                if (amp != null && (amp < 0 || amp > 1)) {
                    throw new ValidationException("request.site.ext.amp must be either 1, 0, or undefined");
                }
            } catch (JsonProcessingException e) {
                throw new ValidationException("request.site.ext object is not valid: %s", e.getMessage());
            }
        }
    }
}
 
Example 3
Source File: ViewAsObjectNode.java    From tasmo with Apache License 2.0 6 votes vote down vote up
@Override
public ViewResponse getView(TenantIdAndCentricId tenantIdAndCentricId, ObjectId viewId, ViewResponse viewResponse) {
    if (viewResponse.getStatusCode() == ViewResponse.StatusCode.OK) {
        ObjectNode view = viewResponse.getViewBody();
        if (view.size() == 0) {
            LOG.debug("Retrieved empty view object for view object id {}. Returning null view object", viewId);
            viewResponse = ViewResponse.notFound();
        } else if (view.has(ReservedFields.DELETED) && view.get(ReservedFields.DELETED).booleanValue()) {
            LOG.debug("Encountered deleted view object with id {}. Returning null view object", viewId);
            viewResponse = ViewResponse.notFound();
        } else {
            view.put(ReservedFields.VIEW_CLASS, viewId.getClassName());
            view.put(ReservedFields.TENANT_ID, tenantIdAndCentricId.getTenantId().toStringForm());
            //view.put(ReservedFields.USER_ID, tenantIdAndCentricId.getUserId().toStringForm());
        }
    }
    return viewResponse;
}
 
Example 4
Source File: JsonDocumentUpdateMarshaller.java    From Cheddar with Apache License 2.0 6 votes vote down vote up
private ObjectNode createJsonNode(final DocumentUpdate document) throws IOException {
    final ObjectNode documentUpdateNode = mapper.createObjectNode();
    documentUpdateNode.put("id", document.getId());
    documentUpdateNode.put("type", document.getType().name().toLowerCase());
    final ObjectNode fields = mapper.createObjectNode();
    for (final Field field : document.getFields()) {
        if (field.getValue() != null) {
            final String fieldValueStr = mapper.writeValueAsString(field.getValue());
            final JsonNode fieldValueJsonNode = mapper.readTree(fieldValueStr);
            fields.put(field.getName().toLowerCase(), fieldValueJsonNode);
        }
    }
    if (fields.size() > 0) {
        documentUpdateNode.put("fields", fields);
    }
    return documentUpdateNode;
}
 
Example 5
Source File: OnosSwaggerMojo.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() throws MojoExecutionException {
    try {
        JavaProjectBuilder builder = new JavaProjectBuilder();
        builder.addSourceTree(new File(srcDirectory, "src/main/java"));

        ObjectNode root = initializeRoot();
        ArrayNode tags = mapper.createArrayNode();
        ObjectNode paths = mapper.createObjectNode();
        ObjectNode definitions = mapper.createObjectNode();

        root.set("tags", tags);
        root.set("paths", paths);
        root.set("definitions", definitions);

        builder.getClasses().forEach(jc -> processClass(jc, paths, tags, definitions));

        if (paths.size() > 0) {
            getLog().info("Generating ONOS REST API documentation...");
            genCatalog(root);

            if (!isNullOrEmpty(apiPackage)) {
                genRegistrator();
            }
        }

        project.addCompileSourceRoot(new File(dstDirectory, GEN_SRC).getPath());

    } catch (Exception e) {
        getLog().warn("Unable to generate ONOS REST API documentation", e);
        throw e;
    }
}
 
Example 6
Source File: StreamsHiveResourceGenerator.java    From streams with Apache License 2.0 5 votes vote down vote up
protected StringBuilder appendRootObject(StringBuilder builder, Schema schema, String resourceId, Character seperator) {
  ObjectNode propertiesNode = schemaStore.resolveProperties(schema, null, resourceId);
  if ( propertiesNode != null && propertiesNode.isObject() && propertiesNode.size() > 0) {
    builder = appendPropertiesNode(builder, schema, propertiesNode, seperator);
  }
  return builder;
}
 
Example 7
Source File: StreamsPigResourceGenerator.java    From streams with Apache License 2.0 5 votes vote down vote up
protected StringBuilder appendRootObject(StringBuilder builder, Schema schema, String resourceId, Character separator) {
  ObjectNode propertiesNode = schemaStore.resolveProperties(schema, null, resourceId);
  if (propertiesNode != null && propertiesNode.isObject() && propertiesNode.size() > 0) {
    builder = appendPropertiesNode(builder, schema, propertiesNode, separator);
  }
  return builder;
}
 
Example 8
Source File: ViewFieldsCollector.java    From tasmo with Apache License 2.0 5 votes vote down vote up
public boolean add(ViewDescriptor viewDescriptor,
        ModelPath modelPath,
        Id[] modelPathIds,
        String[] viewPathClasses,
        ViewValue viewValue,
        Long timestamp) throws IOException {

    byte[] value = (viewValue == null) ? null : viewValue.getValue();
    viewSizeInBytes += (value == null) ? 0 : value.length;
    if (viewSizeInBytes > viewMaxSizeInBytes) {
        LOG.error("ViewDescriptor:" + viewDescriptor + " is larger than viewMaxReadableBytes:" + viewMaxSizeInBytes);
        return false;
    }

    if (viewValue == null || viewValue.getValue() == null || viewValue.getValue().length == 0) {
        return false;
    }
    ObjectNode valueObject = merger.toObjectNode(viewValue.getValue());
    if (valueObject == null || valueObject.isNull() || valueObject.size() == 0) {
        return false;
    }

    ObjectId[] modelPathInstanceIds = modelPathInstanceIds(modelPathIds, viewPathClasses, modelPath.getPathMembers());

    LOG.debug("Read view path -> with id={} instance ids={} value={} timestamp={}", new Object[]{modelPath.getId(), modelPathIds, viewValue, timestamp});

    if (treeRoot == null) {
        treeRoot = new MapTreeNode(modelPathInstanceIds[0]);
    }
    treeRoot.add(modelPath.getPathMembers().toArray(new ModelPathStep[modelPath.getPathMemberSize()]), modelPathInstanceIds, viewValue, timestamp);
    return true;
}
 
Example 9
Source File: TypedValueMapDeserializer.java    From istio-java-api with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, TypedValue> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectCodec codec = p.getCodec();
    ObjectNode root = codec.readTree(p);

    final int size = root.size();
    if (size > 0) {
        final Map<String, TypedValue> values = new HashMap<>(size);
        root.fields().forEachRemaining(field -> values.put(field.getKey(), TypedValue.from(field.getValue().textValue())));
        return values;
    } else {
        return null;
    }
}
 
Example 10
Source File: SchemaBuilder.java    From jsonschema-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Generate an {@link ObjectNode} containing the JSON Schema representation of the given type.
 *
 * @param mainTargetType type for which to generate the JSON Schema
 * @param typeParameters optional type parameters (in case of the {@code mainTargetType} being a parameterised type)
 * @return generated JSON Schema
 */
private ObjectNode createSchemaForSingleType(Type mainTargetType, Type... typeParameters) {
    ResolvedType mainType = this.typeContext.resolve(mainTargetType, typeParameters);
    DefinitionKey mainKey = this.generationContext.parseType(mainType);

    ObjectNode jsonSchemaResult = this.config.createObjectNode();
    if (this.config.shouldIncludeSchemaVersionIndicator()) {
        jsonSchemaResult.put(this.config.getKeyword(SchemaKeyword.TAG_SCHEMA),
                this.config.getKeyword(SchemaKeyword.TAG_SCHEMA_VALUE));
    }
    boolean createDefinitionForMainSchema = this.config.shouldCreateDefinitionForMainSchema();
    if (createDefinitionForMainSchema) {
        this.generationContext.addReference(mainType, jsonSchemaResult, null, false);
    }
    String definitionsTagName = this.config.getKeyword(SchemaKeyword.TAG_DEFINITIONS);
    ObjectNode definitionsNode = this.buildDefinitionsAndResolveReferences(definitionsTagName, mainKey, this.generationContext);
    if (definitionsNode.size() > 0) {
        jsonSchemaResult.set(definitionsTagName, definitionsNode);
    }
    if (!createDefinitionForMainSchema) {
        ObjectNode mainSchemaNode = this.generationContext.getDefinition(mainKey);
        jsonSchemaResult.setAll(mainSchemaNode);
        this.schemaNodes.add(jsonSchemaResult);
    }
    this.performCleanup();
    return jsonSchemaResult;
}
 
Example 11
Source File: JsonConfigWriter.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
private void convertMethodRequestParameters(EndpointMethod endpointMethod, ObjectNode requestNode,
    ObjectNode descriptorSchemasNode, ObjectNode descriptorMethodNode, ApiMethodConfig config,
    ApiConfig apiConfig)
    throws IllegalArgumentException, SecurityException, ApiConfigException {
  ObjectNode parametersNode = objectMapper.createObjectNode();
  Method method = endpointMethod.getMethod();
  List<ApiParameterConfig> parameterConfigs = config.getParameterConfigs();

  for (ApiParameterConfig parameterConfig : parameterConfigs) {
    switch (parameterConfig.getClassification()) {
      case INJECTED:
        // Do nothing.
        break;
      case API_PARAMETER:
        convertSimpleParameter(parameterConfig, parametersNode);
        break;
      case RESOURCE:
        // Inserts resource in.
        convertComplexParameter(parameterConfig, method, descriptorSchemasNode,
            descriptorMethodNode, apiConfig, parameterConfigs);
        break;
      case UNKNOWN:
        throw new IllegalArgumentException("Unclassifiable parameter type found.");
    }
  }
  // Set API parameter types if needed.
  if (parametersNode.size() != 0) {
    requestNode.set("parameters", parametersNode);
  }
  // Sets request body to auto-template if Lily request portion is set..
  if (descriptorMethodNode.get("request") != null) {
    requestNode.put("body", "autoTemplate(backendRequest)");
    requestNode.put("bodyName", "resource");
  } else {
    requestNode.put("body", "empty");
  }
}
 
Example 12
Source File: ExperimentRestRunnerTester.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean isValueValid(final String value) {
	ObjectMapper om = new ObjectMapper();
	JsonNode node;
	try {
		node = om.readTree(value);
	} catch (IOException e) {
		return false;
	}
	if (!(node instanceof ObjectNode)) {
		return false;
	}
	ObjectNode castedNode = (ObjectNode) node;
	return castedNode.size() == 1 && castedNode.has("number") && castedNode.get("number").asInt() <= 2;
}
 
Example 13
Source File: RequestValidator.java    From prebid-server-java with Apache License 2.0 5 votes vote down vote up
private void validateImpExt(ObjectNode ext, Map<String, String> aliases, int impIndex) throws ValidationException {
    if (ext == null || ext.size() < 1) {
        throw new ValidationException("request.imp[%d].ext must contain at least one bidder", impIndex);
    }

    final Iterator<Map.Entry<String, JsonNode>> bidderExtensions = ext.fields();
    while (bidderExtensions.hasNext()) {
        final Map.Entry<String, JsonNode> bidderExtension = bidderExtensions.next();
        final String bidder = bidderExtension.getKey();
        if (!Objects.equals(bidder, PREBID_EXT) && !Objects.equals(bidder, CONTEXT_EXT)) {
            validateImpBidderExtName(impIndex, bidderExtension, aliases.getOrDefault(bidder, bidder));
        }
    }
}
 
Example 14
Source File: RequestValidator.java    From prebid-server-java with Apache License 2.0 5 votes vote down vote up
private void validateDevice(Device device) throws ValidationException {
    final ObjectNode extDeviceNode = device != null ? device.getExt() : null;
    if (extDeviceNode != null && extDeviceNode.size() > 0) {
        final ExtDevice extDevice = parseExtDevice(extDeviceNode);
        final ExtDevicePrebid extDevicePrebid = extDevice.getPrebid();
        final ExtDeviceInt interstitial = extDevicePrebid != null ? extDevicePrebid.getInterstitial() : null;
        if (interstitial != null) {
            validateInterstitial(interstitial);
        }
    }
}
 
Example 15
Source File: RubiconBidder.java    From prebid-server-java with Apache License 2.0 4 votes vote down vote up
private JsonNode makeTarget(Imp imp, ExtImpRubicon rubiconImpExt, Site site, App app, boolean useFirstPartyData) {
    final ObjectNode inventory = rubiconImpExt.getInventory();
    final ObjectNode inventoryNode = inventory == null ? mapper.mapper().createObjectNode() : inventory;

    if (useFirstPartyData) {
        final ExtImpContext context = extImpContext(imp);

        // copy OPENRTB.site.ext.data.* to every impression – XAPI.imp[].ext.rp.target.*
        final ObjectNode siteExt = site != null ? site.getExt() : null;
        if (siteExt != null) {
            populateObjectNode(inventoryNode, getDataNode(siteExt));
        }

        // copy OPENRTB.app.ext.data.* to every impression – XAPI.imp[].ext.rp.target.*
        final ObjectNode appExt = app != null ? app.getExt() : null;
        if (appExt != null) {
            populateObjectNode(inventoryNode, getDataNode(appExt));
        }

        // copy OPENRTB.imp[].ext.context.data.* to XAPI.imp[].ext.rp.target.*
        final ObjectNode contextDataNode = context != null ? context.getData() : null;
        if (contextDataNode != null) {
            inventoryNode.setAll(contextDataNode);

            // copy OPENRTB.imp[].ext.context.data.adslot to XAPI.imp[].ext.rp.target.dfp_ad_unit_code without
            // leading slash
            final JsonNode adSlotNode = contextDataNode.get("adslot");
            if (adSlotNode != null && adSlotNode.isTextual()) {
                final String adSlot = adSlotNode.textValue();
                final String adUnitCode = adSlot.indexOf('/') == 0 ? adSlot.substring(1) : adSlot;
                inventoryNode.put("dfp_ad_unit_code", adUnitCode);
            }
        }

        // copy OPENRTB.imp[].ext.context.keywords to XAPI.imp[].ext.rp.target.keywords
        final String keywords = context != null ? context.getKeywords() : null;
        if (StringUtils.isNotBlank(keywords)) {
            inventoryNode.put("keywords", keywords);
        }

        // copy OPENRTB.imp[].ext.context.search to XAPI.imp[].ext.rp.target.search
        // copy OPENRTB.site.search to every impression XAPI.imp[].ext.rp.target.search
        // imp-specific values should take precedence over global values
        final String contextSearch = context != null ? context.getSearch() : null;
        final String siteSearch = site != null ? site.getSearch() : null;
        final String search = ObjectUtils.defaultIfNull(contextSearch, siteSearch);
        if (StringUtils.isNotBlank(search)) {
            inventoryNode.put("search", search);
        }
    }

    return inventoryNode.size() > 0 ? inventoryNode : null;
}
 
Example 16
Source File: ExtractConnectorDescriptorsMojo.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings({"PMD.EmptyCatchBlock", "PMD.CyclomaticComplexity"})
public void execute() throws MojoExecutionException, MojoFailureException {

    ArrayNode root = new ArrayNode(JsonNodeFactory.instance);

    URLClassLoader classLoader = null;
    try {
        PluginDescriptor desc = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
        List<Artifact> artifacts = desc.getArtifacts();
        ProjectBuildingRequest buildingRequest =
            new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        buildingRequest.setRemoteRepositories(remoteRepositories);
        for (Artifact artifact : artifacts) {
            ArtifactResult result = artifactResolver.resolveArtifact(buildingRequest, artifact);
            File jar = result.getArtifact().getFile();
            classLoader = createClassLoader(jar);
            if (classLoader == null) {
                throw new IOException("Can not create classloader for " + jar);
            }
            ObjectNode entry = new ObjectNode(JsonNodeFactory.instance);
            addConnectorMeta(entry, classLoader);
            addComponentMeta(entry, classLoader);
            if (entry.size() > 0) {
                addGav(entry, artifact);
                root.add(entry);
            }
        }
        if (root.size() > 0) {
            saveCamelMetaData(root);
        }
    } catch (ArtifactResolverException | IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        if (classLoader != null) {
            try {
                classLoader.close();
            } catch (IOException ignored) {

            }
        }
    }
}
 
Example 17
Source File: StreamsHbaseResourceGenerator.java    From streams with Apache License 2.0 4 votes vote down vote up
protected StringBuilder appendRootObject(StringBuilder builder, Schema schema, String resourceId) {
  Objects.requireNonNull(builder);
  ObjectNode propertiesNode = schemaStore.resolveProperties(schema, null, resourceId);
  if ( propertiesNode != null && propertiesNode.isObject() && propertiesNode.size() > 0) {

    List<String> fieldStrings = new ArrayList<>();

    // table
    fieldStrings.add(hbaseEscape(schemaSymbol(schema)));

    // column family
    fieldStrings.add(hbaseEscape(schemaSymbol(schema)));

    // parent column family
    if ( schema.getParent() != null ) {
      fieldStrings.add(hbaseEscape(schemaSymbol(schema.getParent())));
    }

    // sub-object column families
    if ( propertiesNode != null && propertiesNode.isObject() && propertiesNode.size() > 0 ) {

      Iterator<Map.Entry<String, JsonNode>> fields = propertiesNode.fields();
      for ( ; fields.hasNext(); ) {
        Map.Entry<String, JsonNode> field = fields.next();
        String fieldId = field.getKey();
        if ( !config.getExclusions().contains(fieldId) && field.getValue().isObject()) {
          ObjectNode fieldNode = (ObjectNode) field.getValue();
          FieldType fieldType = FieldUtil.determineFieldType(fieldNode);
          if (fieldType != null ) {
            switch (fieldType) {
              case OBJECT:
                fieldStrings.add(hbaseEscape(fieldId));
                break;
              default:
                break;
            }
          }
        }
      }
      builder.append(String.join(", ", fieldStrings));

    }
  }
  Objects.requireNonNull(builder);
  return builder;
}
 
Example 18
Source File: JsonEventConventions.java    From tasmo with Apache License 2.0 4 votes vote down vote up
public void validate(ObjectNode event) {
    Preconditions.checkNotNull(event);
    TenantId tenantId = getTenantId(event);
    int expectedSize = 4;
    if (tenantId == null) {
        throw new IllegalArgumentException("Event is missing tenant id");
    }
    Id actorId = getActor(event);
    if (actorId == null) {
        throw new IllegalArgumentException("Event has missing or invalid actorId:" + actorId);
    }
    Id userId = getUserId(event);
    if (userId == null) {
        throw new IllegalArgumentException("Event has missing or invalid userId:" + userId);
    }
    if (event.has(ReservedFields.CAUSED_BY)) {
        expectedSize++;
    }
    if (event.has(ReservedFields.ACTIVITY_VERB)) {
        expectedSize++;
    }
    if (event.has(ReservedFields.TRACK_EVENT_PROCESSED_LIFECYCLE)) {
        expectedSize++;
    }
    if (event.has(ReservedFields.MODEL_VERSION_ID)) {
        expectedSize++;
    }
    if (event.has(ReservedFields.EVENT_ID)) {
        expectedSize++;
    }
    if (event.has(ReservedFields.EVENT_TYPE)) {
        expectedSize++;
    }
    if (event.has(ReservedFields.TRACE)) {
        expectedSize++;
    }
    String className = Strings.nullToEmpty(getInstanceClassName(event)).trim();
    if (event.has(ReservedFields.NIL_FIELD) || hasInstanceField(event, className, ReservedFields.NIL_FIELD)) {
        throw(new IllegalArgumentException("Nil field may never be emitted"));
    }
    if (Strings.isNullOrEmpty(className)) {
        throw new IllegalArgumentException("Event is missing payload");
    }
    Id instanceId = getInstanceId(event, className);
    if (instanceId == null) {
        throw new IllegalArgumentException("Event is missing instanceId field");
    }
    if (event.size() != expectedSize) {
        throw new IllegalArgumentException("Event does not have the expected number of top level fields. " + event.size() + "!=" + expectedSize);
    }
}
 
Example 19
Source File: JsonldContextFactory.java    From jackson-jsonld with MIT License 4 votes vote down vote up
public static Optional<ObjectNode> fromAnnotations(Iterable<?> instances) {
    ObjectNode mergedContext = JsonNodeFactory.withExactBigDecimals(true).objectNode();
    instances.forEach(e -> fromAnnotations(e).map(mergedContext::setAll));
    return mergedContext.size() != 0 ? Optional.of(mergedContext) : Optional.empty();
}
 
Example 20
Source File: SchemaGenerationContextImpl.java    From jsonschema-generator with Apache License 2.0 4 votes vote down vote up
/**
 * Preparation Step: combine the collected attributes and the javaType's definition in the given targetNode.
 *
 * @param <M> type of target scope, i.e. either a field or method
 * @param scope field's type or method return value's type that should be represented by the given targetNode
 * @param targetNode node in the JSON schema that should represent the associated javaType and include the separately collected attributes
 * @param isNullable whether the field/method's return value the javaType refers to is allowed to be null in the declaringType
 * @param forceInlineDefinition whether to generate an inline definition without registering it in this context
 * @param collectedAttributes separately collected attribute for the field/method in their respective declaring type
 * @param ignoredDefinitionProvider first custom definition provider to ignore
 * @see #populateField(FieldScope, Map, Set)
 * @see #collectMethod(MethodScope, Map, Set)
 */
private <M extends MemberScope<?, ?>> void populateMemberSchema(M scope, ObjectNode targetNode, boolean isNullable, boolean forceInlineDefinition,
        ObjectNode collectedAttributes, CustomPropertyDefinitionProvider<M> ignoredDefinitionProvider) {
    final CustomDefinition customDefinition = this.generatorConfig.getCustomDefinition(scope, this, ignoredDefinitionProvider);
    if (customDefinition != null && customDefinition.isMeantToBeInline()) {
        targetNode.setAll(customDefinition.getValue());
        if (customDefinition.shouldIncludeAttributes()) {
            AttributeCollector.mergeMissingAttributes(targetNode, collectedAttributes);
            Set<String> allowedSchemaTypes = this.collectAllowedSchemaTypes(targetNode);
            ObjectNode typeAttributes = AttributeCollector.collectTypeAttributes(scope, this, allowedSchemaTypes);
            AttributeCollector.mergeMissingAttributes(targetNode, typeAttributes);
        }
        if (isNullable) {
            this.makeNullable(targetNode);
        }
    } else {
        // create an "allOf" wrapper for the attributes related to this particular field and its general type
        final ObjectNode referenceContainer;
        if (customDefinition != null && !customDefinition.shouldIncludeAttributes()
                || collectedAttributes == null || collectedAttributes.size() == 0) {
            // no need for the allOf, can use the sub-schema instance directly as reference
            referenceContainer = targetNode;
        } else if (customDefinition == null && scope.isContainerType()) {
            // same as above, but the collected attributes should be applied also for containers/arrays
            referenceContainer = targetNode;
            AttributeCollector.mergeMissingAttributes(targetNode, collectedAttributes);
        } else {
            // avoid mixing potential "$ref" element with contextual attributes by introducing an "allOf" wrapper
            // this is only relevant for DRAFT_7 and is being cleaned-up afterwards for newer DRAFT versions
            referenceContainer = this.generatorConfig.createObjectNode();
            targetNode.set(this.getKeyword(SchemaKeyword.TAG_ALLOF), this.generatorConfig.createArrayNode()
                    .add(referenceContainer)
                    .add(collectedAttributes));
        }
        // only add reference for separate definition if it is not a fixed type that should be in-lined
        try {
            this.traverseGenericType(scope, referenceContainer, isNullable, forceInlineDefinition, null);
        } catch (UnsupportedOperationException ex) {
            logger.warn("Skipping type definition due to error", ex);
        }
    }
}