List of usage examples for com.fasterxml.jackson.databind.node ObjectNode size
public int size()
From source file:com.clicktravel.infrastructure.persistence.aws.cloudsearch.client.JsonDocumentUpdateMarshaller.java
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); }/*w w w . j a v a 2 s. co m*/ } if (fields.size() > 0) { documentUpdateNode.put("fields", fields); } return documentUpdateNode; }
From source file:com.unboundid.scim2.common.utils.JsonDiff.java
/** * Generates a list of patch operations that can be applied to the source * node in order to make it match the target node. * * @param source The source node for which the set of modifications should * be generated./*from w w w. j a va 2s. c o m*/ * @param target The target node, which is what the source node should * look like if the returned modifications are applied. * @param removeMissing Whether to remove fields that are missing in the * target node. * @return A diff with modifications that can be applied to the source * resource in order to make it match the target resource. */ public List<PatchOperation> diff(final ObjectNode source, final ObjectNode target, final boolean removeMissing) { List<PatchOperation> ops = new LinkedList<PatchOperation>(); ObjectNode targetToAdd = target.deepCopy(); ObjectNode targetToReplace = target.deepCopy(); diff(Path.root(), source, targetToAdd, targetToReplace, ops, removeMissing); if (targetToReplace.size() > 0) { ops.add(PatchOperation.replace(targetToReplace)); } if (targetToAdd.size() > 0) { ops.add(PatchOperation.add(targetToAdd)); } return ops; }
From source file:org.apache.taverna.scufl2.translator.t2flow.defaultdispatchstack.LoopParser.java
@Override public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean, ParserState parserState) throws ReaderException { LoopConfig loopConfig = unmarshallConfig(t2FlowParser, configBean, "xstream", LoopConfig.class); final Configuration c = new Configuration(); c.setType(scufl2Uri.resolve("Config")); ObjectNode json = (ObjectNode) c.getJson(); json.put("runFirst", loopConfig.isRunFirst()); for (Property prop : loopConfig.getProperties().getProperty()) json.put(prop.getName(), prop.getValue()); String conditionXml = loopConfig.getConditionXML(); if (conditionXml == null) // activity is unconfigured (bug in T2). // Return c only if there are properties beyond "runFirst" return json.size() > 1 ? c : null; Activity conditionActivity = unmarshallXml(parserState.getT2FlowParser(), conditionXml, Activity.class); try {//from w w w . j av a2 s. c o m ConditionalActivityParser internalParser = new ConditionalActivityParser(parserState); org.apache.taverna.scufl2.api.activity.Activity newActivity = internalParser .parseActivity(conditionActivity); String name = parserState.getCurrentProcessor().getName() + "-loop"; newActivity.setName(name); parserState.getCurrentProfile().getActivities().addWithUniqueName(newActivity); newActivity.setParent(parserState.getCurrentProfile()); Configuration newConfig = internalParser.parseConfiguration(conditionActivity.getConfigBean()); newConfig.setName(name); newConfig.setConfigures(newActivity); parserState.getCurrentProfile().getConfigurations().addWithUniqueName(newConfig); // URI uriActivity = uriTools.relativeUriForBean(newActivity, parserState.getCurrentProfile()); json.put("conditionActivity", newActivity.getName()); } catch (JAXBException e) { throw new ReaderException("Can't parse conditional loop activity", e); } return c; }
From source file:io.syndesis.maven.ExtractConnectorDescriptorsMojo.java
private void addComponentMeta(ObjectNode root, ClassLoader classLoader) { // is there any custom Camel components in this library? ObjectNode component = new ObjectNode(JsonNodeFactory.instance); ObjectNode componentMeta = getComponentMeta(classLoader); if (componentMeta != null) { component.set("meta", componentMeta); }//from ww w . j av a2 s . c o m addOptionalSchemaAsString(classLoader, component, "schema", "camel-component-schema.json"); if (component.size() > 0) { root.set("component", component); } }
From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java
public static ObjectNode createSchemaDesignObjectNode(final ObjectMapper objectMapper, final Schema schema) { final Context context = schema.getContext(); final SyntaxLoader syntaxLoader = context.getSyntaxLoader(); final SchemaLoader schemaLoader = context.getSchemaLoader(); final ObjectNode rootNode = objectMapper.createObjectNode(); final URI schemaUri = schema.getUri(); final Prototype prototype = schemaLoader.getPrototype(schemaUri); rootNode.put(PropertyName.uri.name(), syntaxLoader.formatSyntaxValue(schemaUri)); rootNode.put(PropertyName.title.name(), schema.getTitle()); rootNode.put(PropertyName.description.name(), schema.getDescription()); rootNode.put(PropertyName.version.name(), schema.getVersion()); final String titleSlotName = getTitleSlotName(schemaUri, schemaLoader); if (titleSlotName != null) { rootNode.put(PropertyName.titleSlotName.name(), titleSlotName); }/*from ww w.j a va 2 s. com*/ final UniqueName uniqueName = schema.getUniqueName(); final ObjectNode uniqueNameNode = objectMapper.createObjectNode(); uniqueNameNode.put(PropertyName.fullName.name(), uniqueName.getFullName()); uniqueNameNode.put(PropertyName.namespace.name(), uniqueName.getNamespace()); uniqueNameNode.put(PropertyName.localName.name(), uniqueName.getLocalName()); rootNode.put(PropertyName.uniqueName.name(), uniqueNameNode); final Set<URI> declaredBaseSchemaUris = prototype.getDeclaredBaseSchemaUris(); if (declaredBaseSchemaUris != null && !declaredBaseSchemaUris.isEmpty()) { final Set<URI> addedBaseSchemaUris = new LinkedHashSet<>(); final ArrayNode baseSchemasNode = objectMapper.createArrayNode(); rootNode.put(PropertyName.baseSchemas.name(), baseSchemasNode); for (final URI baseSchemaUri : declaredBaseSchemaUris) { if (!addedBaseSchemaUris.contains(baseSchemaUri)) { final ObjectNode baseSchemaNode = buildSchemaNode(objectMapper, baseSchemaUri, schemaLoader, addedBaseSchemaUris); baseSchemasNode.add(baseSchemaNode); addedBaseSchemaUris.add(baseSchemaUri); } } } final Set<String> keySlotNames = prototype.getDeclaredKeySlotNames(); if (keySlotNames != null && !keySlotNames.isEmpty()) { final ArrayNode keyPropertyNamesNode = objectMapper.createArrayNode(); for (final String keySlotName : keySlotNames) { keyPropertyNamesNode.add(keySlotName); } if (keyPropertyNamesNode.size() > 0) { rootNode.put(PropertyName.keyPropertyNames.name(), keyPropertyNamesNode); } } final Set<String> allKeySlotNames = prototype.getAllKeySlotNames(); final ArrayNode allKeySlotNamesNode = objectMapper.createArrayNode(); rootNode.put(PropertyName.allKeySlotNames.name(), allKeySlotNamesNode); final ObjectNode keySlotMap = objectMapper.createObjectNode(); rootNode.put(PropertyName.keys.name(), keySlotMap); final String uriSlotName = PropertyName.uri.name(); if (allKeySlotNames.contains(uriSlotName)) { allKeySlotNamesNode.add(uriSlotName); final ObjectNode slot = createSlot(objectMapper, prototype, uriSlotName); keySlotMap.put(uriSlotName, slot); } for (final String keySlotName : allKeySlotNames) { if (!Document.SLOT_NAME_URI.equals(keySlotName)) { allKeySlotNamesNode.add(keySlotName); final ObjectNode slot = createSlot(objectMapper, prototype, keySlotName); keySlotMap.put(keySlotName, slot); } } rootNode.put(PropertyName.keyCount.name(), keySlotMap.size()); final SortedSet<String> allSlotNames = prototype.getAllSlotNames(); if (allSlotNames != null && !allSlotNames.isEmpty()) { final ObjectNode slotMapNode = objectMapper.createObjectNode(); rootNode.put(PropertyName.slots.name(), slotMapNode); final ArrayNode propertyNamesNode = objectMapper.createArrayNode(); for (final String slotName : allSlotNames) { final ProtoSlot protoSlot = prototype.getProtoSlot(slotName); if (protoSlot instanceof LinkProtoSlot) { continue; } if (allKeySlotNames.contains(slotName)) { // Skip key slots (handled separately) continue; } if (protoSlot.getDeclaringSchemaUri().equals(schemaUri)) { propertyNamesNode.add(slotName); } final ObjectNode slotNode = createSlot(objectMapper, prototype, slotName); if (slotNode != null) { slotMapNode.put(slotName, slotNode); } } if (propertyNamesNode.size() > 0) { rootNode.put(PropertyName.propertyNames.name(), propertyNamesNode); } rootNode.put(PropertyName.slotCount.name(), slotMapNode.size()); } final Set<String> comparablePropertyNames = prototype.getComparableSlotNames(); if (comparablePropertyNames != null && !comparablePropertyNames.isEmpty()) { final ArrayNode comparablePropertyNamesNode = objectMapper.createArrayNode(); for (final String comparablePropertyName : comparablePropertyNames) { comparablePropertyNamesNode.add(comparablePropertyName); } if (comparablePropertyNamesNode.size() > 0) { rootNode.put(PropertyName.comparablePropertyNames.name(), comparablePropertyNamesNode); } } final Collection<LinkProtoSlot> linkProtoSlots = prototype.getLinkProtoSlots().values(); if (linkProtoSlots != null && !linkProtoSlots.isEmpty()) { final ArrayNode linkNamesNode = objectMapper.createArrayNode(); final ObjectNode linksMapNode = objectMapper.createObjectNode(); rootNode.put(PropertyName.links.name(), linksMapNode); for (final LinkProtoSlot linkProtoSlot : linkProtoSlots) { if (linkProtoSlot.getDeclaringSchemaUri().equals(schemaUri)) { linkNamesNode.add(linkProtoSlot.getName()); } final ObjectNode linkNode = objectMapper.createObjectNode(); String linkTitle = linkProtoSlot.getTitle(); if (linkTitle == null) { linkTitle = linkProtoSlot.getName(); } linkNode.put(PropertyName.name.name(), linkProtoSlot.getName()); linkNode.put(PropertyName.title.name(), linkTitle); final Method method = linkProtoSlot.getMethod(); final URI linkRelationUri = linkProtoSlot.getLinkRelationUri(); final URI declaringSchemaUri = linkProtoSlot.getDeclaringSchemaUri(); linkNode.put(PropertyName.rel.name(), syntaxLoader.formatSyntaxValue(linkRelationUri)); final Keys linkRelationKeys = context.getApiLoader().buildDocumentKeys(linkRelationUri, schemaLoader.getLinkRelationSchemaUri()); final LinkRelation linkRelation = context.getModel(linkRelationKeys, schemaLoader.getLinkRelationDimensions()); linkNode.put(PropertyName.relationTitle.name(), linkRelation.getTitle()); linkNode.put(PropertyName.description.name(), linkProtoSlot.getDescription()); linkNode.put(PropertyName.method.name(), method.getProtocolGivenName()); linkNode.put(PropertyName.declaringSchemaUri.name(), syntaxLoader.formatSyntaxValue(declaringSchemaUri)); URI requestSchemaUri = linkProtoSlot.getRequestSchemaUri(); if (schemaLoader.getDocumentSchemaUri().equals(requestSchemaUri)) { if (SystemLinkRelation.self.getUri().equals(linkRelationUri) || SystemLinkRelation.save.getUri().equals(linkRelationUri)) { requestSchemaUri = schemaUri; } } if (requestSchemaUri == null && method == Method.Save) { requestSchemaUri = schemaUri; } if (requestSchemaUri != null) { linkNode.put(PropertyName.requestSchemaUri.name(), syntaxLoader.formatSyntaxValue(requestSchemaUri)); final Schema requestSchema = schemaLoader.load(requestSchemaUri); if (requestSchema != null) { linkNode.put(PropertyName.requestSchemaTitle.name(), requestSchema.getTitle()); } } URI responseSchemaUri = linkProtoSlot.getResponseSchemaUri(); if (schemaLoader.getDocumentSchemaUri().equals(responseSchemaUri)) { if (SystemLinkRelation.self.getUri().equals(linkRelationUri) || SystemLinkRelation.save.getUri().equals(linkRelationUri)) { responseSchemaUri = schemaUri; } } if (responseSchemaUri != null) { linkNode.put(PropertyName.responseSchemaUri.name(), syntaxLoader.formatSyntaxValue(responseSchemaUri)); final Schema responseSchema = schemaLoader.load(responseSchemaUri); if (responseSchema != null) { linkNode.put(PropertyName.responseSchemaTitle.name(), responseSchema.getTitle()); } } linksMapNode.put(linkTitle, linkNode); } if (linkNamesNode.size() > 0) { rootNode.put(PropertyName.linkNames.name(), linkNamesNode); } rootNode.put(PropertyName.linkCount.name(), linksMapNode.size()); } return rootNode; }
From source file:org.modeshape.web.jcr.rest.handler.ItemHandlerImpl.java
protected List<JSONChild> getChildren(JsonNode jsonNode) { List<JSONChild> children; JsonNode childrenNode = jsonNode.get(CHILD_NODE_HOLDER); if (childrenNode instanceof ObjectNode) { ObjectNode childrenObject = (ObjectNode) childrenNode; children = new ArrayList<>(childrenObject.size()); for (Iterator<?> iterator = childrenObject.fields(); iterator.hasNext();) { String childName = iterator.next().toString(); //it is not possible to have SNS in the object form, so the index will always be 1 children.add(new JSONChild(childName, childrenObject.get(childName), 1)); }//www . ja va 2s.c o m return children; } else { ArrayNode childrenArray = (ArrayNode) childrenNode; children = new ArrayList<>(childrenArray.size()); Map<String, Integer> visitedNames = new HashMap<>(childrenArray.size()); for (int i = 0; i < childrenArray.size(); i++) { JsonNode child = childrenArray.get(i); if (child.size() == 0) { continue; } if (child.size() > 1) { logger.warn( "The child object {0} has more than 1 elements, only the first one will be taken into account", child); } String childName = child.fields().next().toString(); int sns = visitedNames.containsKey(childName) ? visitedNames.get(childName) + 1 : 1; visitedNames.put(childName, sns); children.add(new JSONChild(childName, child.get(childName), sns)); } return children; } }
From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.ObjectConstructionExpressionEvaluator.java
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); }/*from w w w . j a v a 2s . com*/ } } if (newNode.size() > 0) { return from.createChild(newNode); } return null; }
From source file:io.syndesis.maven.ExtractConnectorDescriptorsMojo.java
private ObjectNode getComponentMeta(ClassLoader classLoader) { Properties properties = loadComponentProperties(classLoader); if (properties == null) { return null; }/*from www .j a va 2 s . c o m*/ String components = (String) properties.get("components"); if (components == null) { return null; } String[] part = components.split("\\s"); ObjectNode componentMeta = new ObjectNode(JsonNodeFactory.instance); for (String scheme : part) { // find the class name String javaType = extractComponentJavaType(classLoader, scheme); if (javaType == null) { continue; } String schemeMeta = loadComponentJSonSchema(classLoader, scheme, javaType); if (schemeMeta == null) { continue; } componentMeta.set(scheme, new TextNode(schemeMeta)); } return componentMeta.size() > 0 ? componentMeta : null; }
From source file:org.onosproject.maven.OnosSwaggerMojo.java
@Override public void execute() throws MojoExecutionException { try {// w ww .j av a2 s . co m 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; } }
From source file:org.wrml.runtime.format.text.html.WrmldocFormatter.java
protected ObjectNode buildResourceNode(final ObjectMapper objectMapper, final Map<URI, ObjectNode> schemaNodes, final Map<URI, LinkRelation> linkRelationCache, final ApiNavigator apiNavigator, final Resource resource) { final Context context = getContext(); final SchemaLoader schemaLoader = context.getSchemaLoader(); final SyntaxLoader syntaxLoader = context.getSyntaxLoader(); final ObjectNode resourceNode = objectMapper.createObjectNode(); resourceNode.put(PropertyName.id.name(), syntaxLoader.formatSyntaxValue(resource.getResourceTemplateId())); resourceNode.put(PropertyName.pathSegment.name(), resource.getPathSegment()); resourceNode.put(PropertyName.fullPath.name(), resource.getPathText()); final String parentPathText = resource.getParentPathText(); if (parentPathText != null) { resourceNode.put(PropertyName.parentPath.name(), parentPathText); }//from w w w . j a v a 2 s . com resourceNode.put(PropertyName.uriTemplate.name(), resource.getUriTemplate().getUriTemplateString()); final URI defaultSchemaUri = resource.getDefaultSchemaUri(); Prototype defaultPrototype = null; if (defaultSchemaUri != null) { final ObjectNode defaultSchemaNode = getSchemaNode(objectMapper, schemaNodes, defaultSchemaUri, schemaLoader); resourceNode.put(PropertyName.defaultSchema.name(), defaultSchemaNode); defaultPrototype = schemaLoader.getPrototype(defaultSchemaUri); } final ArrayNode referencesNode = buildReferencesArrayNode(objectMapper, schemaNodes, linkRelationCache, resource, defaultPrototype); if (referencesNode.size() > 0) { resourceNode.put(PropertyName.references.name(), referencesNode); } final ObjectNode linksNode = buildLinksNode(objectMapper, schemaNodes, linkRelationCache, apiNavigator, resource, defaultPrototype); if (linksNode.size() > 0) { resourceNode.put(PropertyName.links.name(), linksNode); } return resourceNode; }