Java Code Examples for com.fasterxml.jackson.databind.node.ArrayNode#add()

The following examples show how to use com.fasterxml.jackson.databind.node.ArrayNode#add() . 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: CmmnModelJsonConverterUtil.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public static void addEventCorrelationParameters(List<ExtensionElement> eventParameterElements, ObjectNode propertiesNode, ObjectMapper objectMapper) {
    if (CollectionUtils.isEmpty(eventParameterElements)) {
        return;
    }

    ObjectNode valueNode = objectMapper.createObjectNode();
    ArrayNode arrayNode = objectMapper.createArrayNode();
    for (ExtensionElement element : eventParameterElements) {
        ObjectNode itemNode = objectMapper.createObjectNode();
        itemNode.put(PROPERTY_EVENT_REGISTRY_CORRELATIONNAME, element.getAttributeValue(null, "name"));
        itemNode.put(PROPERTY_EVENT_REGISTRY_CORRELATIONTYPE, element.getAttributeValue(null, "nameType"));
        itemNode.put(PROPERTY_EVENT_REGISTRY_CORRELATIONVALUE, element.getAttributeValue(null, "value"));

        arrayNode.add(itemNode);
    }

    valueNode.set("correlationParameters", arrayNode);
    propertiesNode.set(PROPERTY_EVENT_REGISTRY_CORRELATION_PARAMETERS, valueNode);
}
 
Example 2
Source File: CompilerOptionsParserTests.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
@Test
void testTargetsWithOneValue()
{
	String value1 = "JS";

	ObjectNode options = JsonNodeFactory.instance.objectNode();
	ArrayNode targets = JsonNodeFactory.instance.arrayNode();

	targets.add(JsonNodeFactory.instance.textNode(value1));

	options.set(CompilerOptions.TARGETS, targets);

	ArrayList<String> result = new ArrayList<>();
	try
	{
		parser.parse(options, null, result);
	}
	catch(UnknownCompilerOptionException e) {}
	Assertions.assertEquals(1, result.size(),
		"CompilerOptionsParser.parse() created incorrect number of options.");
	Assertions.assertEquals("--" + CompilerOptions.TARGETS + "=" + value1, result.get(0),
		"CompilerOptionsParser.parse() incorrectly formatted compiler option.");
}
 
Example 3
Source File: PathListCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Produces a JSON array containing the specified paths.
 *
 * @param context context to use for looking up codecs
 * @param paths collection of paths
 * @return JSON array
 */
public static JsonNode json(AbstractShellCommand context,
                            Iterable<? extends Path> paths) {
    ObjectMapper mapper = context.mapper();
    ArrayNode result = mapper.createArrayNode();
    for (Path path : paths) {
        result.add(LinksListCommand.json(context, path)
                .put("cost", path.cost())
                .set("links", LinksListCommand.json(context, path.links())));

        if (path instanceof DisjointPath) {
            // [ (primay), (backup), ...]
            DisjointPath backup = (DisjointPath) path;
            result.add(LinksListCommand.json(context, backup.backup())
                       .put("cost", backup.cost())
                       .set("links", LinksListCommand.json(context, backup.links())));
        }
    }
    return result;
}
 
Example 4
Source File: JacksonHandleTest.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadWrite() {
  // create an identifier for the database document
  String docId = "/example/jackson-test.json";

  // create a manager for JSON documents
  JSONDocumentManager docMgr = Common.client.newJSONDocumentManager();

  // construct a Jackson JSON structure
  ObjectMapper mapper = new ObjectMapper();
  ObjectNode childObj = mapper.createObjectNode();
  childObj.put("key", "value");
  ArrayNode childArray = mapper.createArrayNode();
  childArray.add("item1");
  childArray.add("item2");
  ObjectNode writeRoot = mapper.createObjectNode();
  writeRoot.put("object", childObj);
  writeRoot.put("array",  childArray);

  // create a handle for the JSON structure
  JacksonHandle writeHandle = new JacksonHandle(writeRoot);

  // write the document to the database
  docMgr.write(docId, writeHandle);

  // create a handle to receive the database content as a Jackson structure
  JacksonHandle readHandle = new JacksonHandle();

  // read the document content from the database as a Jackson structure
  docMgr.read(docId, readHandle);

  // access the document content
  JsonNode readRoot = readHandle.get();
  assertNotNull("Wrote null Jackson JSON structure", readRoot);
  assertTrue("Jackson JSON structures not equal",
    readRoot.equals(writeRoot));

  // delete the document
  docMgr.delete(docId);
}
 
Example 5
Source File: PublishMessage.java    From jlibs with Apache License 2.0 5 votes vote down vote up
@Override
public void toArrayNode(ArrayNode array){
    array.add(idNodes[ID]);
    array.add(requestID);
    array.add(objectNode(options));
    array.add(topic);
    if(arguments!=null)
        array.add(arguments);
    if(argumentsKw!=null)
        array.add(argumentsKw);
}
 
Example 6
Source File: ProcessInstanceMigrationDocumentConverter.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected static ArrayNode convertToJsonActivityMigrationMappings(List<? extends ActivityMigrationMapping> activityMigrationMappings) {
    ArrayNode mappingsArray = objectMapper.createArrayNode();

    for (ActivityMigrationMapping mapping : activityMigrationMappings) {
        BaseActivityMigrationMappingConverter mappingConverter = activityMigrationMappingConverters.get(mapping.getClass());
        if (mappingConverter == null) {
            throw new FlowableException("Cannot convert mapping of type '" + mapping.getClass() + "'");
        }
        ObjectNode mappingNode = mappingConverter.convertToJson(mapping, objectMapper);
        mappingsArray.add(mappingNode);
    }

    return mappingsArray;
}
 
Example 7
Source File: WampMessages.java    From jawampa with Apache License 2.0 5 votes vote down vote up
public JsonNode toObjectArray(ObjectMapper mapper) throws WampError {
    ArrayNode messageNode = mapper.createArrayNode();
    messageNode.add(ID);
    messageNode.add(requestId);
    if (options != null)
        messageNode.add(options);
    else
        messageNode.add(mapper.createObjectNode());
    messageNode.add(topic);
    return messageNode;
}
 
Example 8
Source File: WampMessages.java    From jawampa with Apache License 2.0 5 votes vote down vote up
public JsonNode toObjectArray(ObjectMapper mapper) throws WampError {
    ArrayNode messageNode = mapper.createArrayNode();
    messageNode.add(ID);
    if (details != null)
        messageNode.add(details);
    else
        messageNode.add(mapper.createObjectNode());
    messageNode.add(reason);
    return messageNode;
}
 
Example 9
Source File: BgpRoutesListCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Produces a JSON array of routes.
 *
 * @param routes the routes with the data
 * @return JSON array with the routes
 */
private JsonNode json(Collection<BgpRouteEntry> routes) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();

    for (BgpRouteEntry route : routes) {
        result.add(json(mapper, route));
    }
    return result;
}
 
Example 10
Source File: ControlMetricsWebResource.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms control load snapshot object into JSON object.
 *
 * @param cls         control load snapshot
 * @param type        control metric type
 * @param metricsNode array of JSON node
 */
private void processRest(ControlLoadSnapshot cls, ControlMetricType type, ArrayNode metricsNode) {
    ObjectNode metricNode = mapper().createObjectNode();

    if (cls != null) {
        metricNode.set(toCamelCase(type.toString(), true),
                codec(ControlLoadSnapshot.class).encode(cls, this));
        metricsNode.add(metricNode);
    }
}
 
Example 11
Source File: RuntimeDisplayJsonClientResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void fillWaypoints(String id, BpmnModel model, ObjectNode elementNode, GraphicInfo diagramInfo) {
  List<GraphicInfo> flowInfo = model.getFlowLocationGraphicInfo(id);
  ArrayNode waypointArray = objectMapper.createArrayNode();
  for (GraphicInfo graphicInfo : flowInfo) {
    ObjectNode pointNode = objectMapper.createObjectNode();
    fillGraphicInfo(pointNode, graphicInfo, false);
    waypointArray.add(pointNode);
    fillDiagramInfo(graphicInfo, diagramInfo);
  }
  elementNode.put("waypoints", waypointArray);
}
 
Example 12
Source File: OntologyRest.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
private ArrayNode doWithOntologies(Set<Ontology> ontologies, Function<Ontology, ObjectNode> function) {
    ArrayNode arrayNode = mapper.createArrayNode();
    for (Ontology ontology : ontologies) {
        ObjectNode object = function.apply(ontology);
        object.put("id", ontology.getOntologyId().getOntologyIdentifier().stringValue());
        arrayNode.add(object);
    }
    return arrayNode;
}
 
Example 13
Source File: FieldEncoder.java    From arctic-sea with Apache License 2.0 5 votes vote down vote up
private ObjectNode encodeSweQuantityRangeField(SweField field) {
    ObjectNode jfield = createField(field);
    jfield.put(JSONConstants.TYPE, JSONConstants.QUANTITY_RANGE_TYPE);
    SweQuantityRange sweQuantityRange = (SweQuantityRange) field.getElement();
    jfield.put(JSONConstants.UOM, sweQuantityRange.getUom());
    if (sweQuantityRange.isSetValue()) {
        ArrayNode av = jfield.putArray(JSONConstants.VALUE);
        av.add(sweQuantityRange.getValue().getRangeStart());
        av.add(sweQuantityRange.getValue().getRangeEnd());
    }
    return jfield;
}
 
Example 14
Source File: DynamicBpmnServiceImpl.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void changeUserTaskCandidateUsers(String id, List<String> candidateUsers, ObjectNode infoNode) {
    ArrayNode candidateUsersNode = configuration.getObjectMapper().createArrayNode();
    for (String candidateUser : candidateUsers) {
        candidateUsersNode.add(candidateUser);
    }
    setElementProperty(id, USER_TASK_CANDIDATE_USERS, candidateUsersNode, infoNode);
}
 
Example 15
Source File: WampMessages.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
public JsonNode toObjectArray(ObjectMapper mapper) throws WampError {
    ArrayNode messageNode = mapper.createArrayNode();
    messageNode.add(ID);
    messageNode.add(sessionId);
    if (details != null)
        messageNode.add(details);
    else
        messageNode.add(mapper.createObjectNode());
    return messageNode;
}
 
Example 16
Source File: OpenstackFloatingIpListCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
private String json(List<NetFloatingIP> floatingIps) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();
    for (NetFloatingIP floatingIp: floatingIps) {
        result.add(modelEntityToJson(floatingIp, NeutronFloatingIP.class));
    }
    return prettyJson(mapper, result.toString());
}
 
Example 17
Source File: BoundaryEventJsonConverter.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
  BoundaryEvent boundaryEvent = (BoundaryEvent) baseElement;
  ArrayNode dockersArrayNode = objectMapper.createArrayNode();
  ObjectNode dockNode = objectMapper.createObjectNode();
  GraphicInfo graphicInfo = model.getGraphicInfo(boundaryEvent.getId());
  GraphicInfo parentGraphicInfo = model.getGraphicInfo(boundaryEvent.getAttachedToRef().getId());
  dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX() - parentGraphicInfo.getX());
  dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY() - parentGraphicInfo.getY());
  dockersArrayNode.add(dockNode);
  flowElementNode.set("dockers", dockersArrayNode);

  propertiesNode.put(PROPERTY_CANCEL_ACTIVITY, boundaryEvent.isCancelActivity());

  addEventProperties(boundaryEvent, propertiesNode);
}
 
Example 18
Source File: JsonSubTypesResolver.java    From jsonschema-generator with Apache License 2.0 4 votes vote down vote up
/**
 * Create the custom schema definition for the given subtype, considering the {@link JsonTypeInfo#include()} setting.
 *
 * @param javaType targeted subtype
 * @param typeInfoAnnotation annotation for looking up the type identifier and determining the kind of inclusion/serialization
 * @param attributesToInclude optional: additional attributes to include on the actual/contained schema definition
 * @param context generation context
 * @return created custom definition (or {@code null} if no supported subtype resolution scenario could be detected
 */
private ObjectNode createSubtypeDefinition(ResolvedType javaType, JsonTypeInfo typeInfoAnnotation, ObjectNode attributesToInclude,
        SchemaGenerationContext context) {
    final String typeIdentifier = this.getTypeIdentifier(javaType, typeInfoAnnotation);
    if (typeIdentifier == null) {
        return null;
    }
    final ObjectNode definition = context.getGeneratorConfig().createObjectNode();
    switch (typeInfoAnnotation.include()) {
    case WRAPPER_ARRAY:
        definition.put(context.getKeyword(SchemaKeyword.TAG_TYPE), context.getKeyword(SchemaKeyword.TAG_TYPE_ARRAY));
        ArrayNode itemsArray = definition.withArray(context.getKeyword(SchemaKeyword.TAG_ITEMS));
        itemsArray.addObject()
                .put(context.getKeyword(SchemaKeyword.TAG_TYPE), context.getKeyword(SchemaKeyword.TAG_TYPE_STRING))
                .put(context.getKeyword(SchemaKeyword.TAG_CONST), typeIdentifier);
        if (attributesToInclude == null || attributesToInclude.isEmpty()) {
            itemsArray.add(context.createStandardDefinitionReference(javaType, this));
        } else {
            itemsArray.addObject()
                    .withArray(context.getKeyword(SchemaKeyword.TAG_ALLOF))
                    .add(context.createStandardDefinitionReference(javaType, this))
                    .add(attributesToInclude);
        }
        break;
    case WRAPPER_OBJECT:
        definition.put(context.getKeyword(SchemaKeyword.TAG_TYPE), context.getKeyword(SchemaKeyword.TAG_TYPE_OBJECT));
        ObjectNode propertiesNode = definition.with(context.getKeyword(SchemaKeyword.TAG_PROPERTIES));
        if (attributesToInclude == null || attributesToInclude.isEmpty()) {
            propertiesNode.set(typeIdentifier, context.createStandardDefinitionReference(javaType, this));
        } else {
            propertiesNode.with(typeIdentifier)
                    .withArray(context.getKeyword(SchemaKeyword.TAG_ALLOF))
                    .add(context.createStandardDefinitionReference(javaType, this))
                    .add(attributesToInclude);
        }
        break;
    case PROPERTY:
    case EXISTING_PROPERTY:
        final String propertyName = Optional.ofNullable(typeInfoAnnotation.property())
                .filter(name -> !name.isEmpty())
                .orElseGet(() -> typeInfoAnnotation.use().getDefaultPropertyName());
        ObjectNode additionalPart = definition.withArray(context.getKeyword(SchemaKeyword.TAG_ALLOF))
                .add(context.createStandardDefinitionReference(javaType, this))
                .addObject();
        if (attributesToInclude != null && !attributesToInclude.isEmpty()) {
            additionalPart.setAll(attributesToInclude);
        }
        additionalPart.put(context.getKeyword(SchemaKeyword.TAG_TYPE), context.getKeyword(SchemaKeyword.TAG_TYPE_OBJECT))
                .with(context.getKeyword(SchemaKeyword.TAG_PROPERTIES))
                .with(propertyName)
                .put(context.getKeyword(SchemaKeyword.TAG_CONST), typeIdentifier);
        break;
    default:
        return null;
    }
    return definition;
}
 
Example 19
Source File: AssociationJsonConverter.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void convertToJson(BpmnJsonConverterContext converterContext, BaseElement baseElement, ActivityProcessor processor, BpmnModel model,
        FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {

    Association association = (Association) baseElement;
    ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape(association.getId(), STENCIL_ASSOCIATION, 172, 212, 128, 212);
    ArrayNode dockersArrayNode = objectMapper.createArrayNode();
    ObjectNode dockNode = objectMapper.createObjectNode();
    dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(association.getSourceRef()).getWidth() / 2.0);
    dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(association.getSourceRef()).getHeight() / 2.0);
    dockersArrayNode.add(dockNode);

    List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(association.getId());
    if (graphicInfoList.size() > 2) {
        for (int i = 1; i < graphicInfoList.size() - 1; i++) {
            GraphicInfo graphicInfo = graphicInfoList.get(i);
            dockNode = objectMapper.createObjectNode();
            dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
            dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
            dockersArrayNode.add(dockNode);
        }
    }

    GraphicInfo targetGraphicInfo = model.getGraphicInfo(association.getTargetRef());
    GraphicInfo flowGraphicInfo = graphicInfoList.get(graphicInfoList.size() - 1);

    double diffTopY = Math.abs(flowGraphicInfo.getY() - targetGraphicInfo.getY());
    double diffRightX = Math.abs(flowGraphicInfo.getX() - (targetGraphicInfo.getX() + targetGraphicInfo.getWidth()));
    double diffBottomY = Math.abs(flowGraphicInfo.getY() - (targetGraphicInfo.getY() + targetGraphicInfo.getHeight()));

    dockNode = objectMapper.createObjectNode();
    if (diffTopY < 5) {
        dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth() / 2.0);
        dockNode.put(EDITOR_BOUNDS_Y, 0.0);

    } else if (diffRightX < 5) {
        dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth());
        dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight() / 2.0);

    } else if (diffBottomY < 5) {
        dockNode.put(EDITOR_BOUNDS_X, targetGraphicInfo.getWidth() / 2.0);
        dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight());

    } else {
        dockNode.put(EDITOR_BOUNDS_X, 0.0);
        dockNode.put(EDITOR_BOUNDS_Y, targetGraphicInfo.getHeight() / 2.0);
    }
    dockersArrayNode.add(dockNode);
    flowNode.set("dockers", dockersArrayNode);
    ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
    outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getTargetRef()));
    flowNode.set("outgoing", outgoingArrayNode);
    flowNode.set("target", BpmnJsonConverterUtil.createResourceNode(association.getTargetRef()));

    ObjectNode propertiesNode = objectMapper.createObjectNode();
    propertiesNode.put(PROPERTY_OVERRIDE_ID, association.getId());

    flowNode.set(EDITOR_SHAPE_PROPERTIES, propertiesNode);

    shapesArrayNode.add(flowNode);
}
 
Example 20
Source File: AstEmitter.java    From template-compiler with Apache License 2.0 4 votes vote down vote up
private static ArrayNode composite(Instruction inst) {
  ArrayNode array = JsonUtils.createArrayNode();
  array.add(type(inst.getType()));
  return array;
}