List of usage examples for com.fasterxml.jackson.databind ObjectMapper createArrayNode
@Override
public ArrayNode createArrayNode()
Note: return type is co-variant, as basic ObjectCodec abstraction can not refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)
From source file:gist.ac.netcs.fwdtraffic.FwdTrafficComponent.java
private JsonNode json(IntentService service, Iterable<Intent> intents) { ObjectMapper mapper = new ObjectMapper(); ArrayNode result = mapper.createArrayNode(); intents.forEach(intent -> result.add(jsonForEntity(intent, Intent.class))); return result; }
From source file:ijfx.service.ui.ImageJInfoService.java
@AngularMethod(sync = true, description = "Return the list of all widgets", inputDescription = "No input") public JSObject getModuleList() { try {//from w w w . j a v a2 s. c o m ObjectMapper mapper = new ObjectMapper(); logger.fine("Getting module list"); SimpleModule simpleModule = new SimpleModule("ModuleSerializer"); // simpleModule.addSerializer(ModuleItem<?>.class,new ModuleItemSerializer()); simpleModule.addSerializer(ModuleInfo.class, new ModuleSerializer()); simpleModule.addSerializer(ModuleItem.class, new ModuleItemSerializer()); mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.registerModule(simpleModule); ArrayNode arrayNode = mapper.createArrayNode(); moduleService.getModules().forEach(module -> { //System.out.println("Adding "+module.getName()); arrayNode.add(mapper.convertValue(module, JsonNode.class)); }); //String json = mapper.writeValueAsString(moduleService.getModules()); logger.fine("JSON done !"); return JSONUtils.parseToJSON(appService.getCurrentWebEngine(), arrayNode.toString()); //return JSONUtils.parseToJSON(appService.getCurrentWebEngine(), json); } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); } logger.warning("Returning null"); return null; }
From source file:org.onosproject.tvue.TopologyResource.java
@javax.ws.rs.Path("/graph") @GET//from www .j a v a 2 s . c o m @Produces("application/json") public Response graph() { ObjectMapper mapper = new ObjectMapper(); // Fetch the services we'll be using. DeviceService deviceService = get(DeviceService.class); HostService hostService = get(HostService.class); TopologyService topologyService = get(TopologyService.class); // Fetch the current topology and its graph that we'll use to render. Topology topo = topologyService.currentTopology(); TopologyGraph graph = topologyService.getGraph(topo); // Build all interior vertexes, i.e. no end-station hosts yet ArrayNode vertexesNode = mapper.createArrayNode(); for (TopologyVertex vertex : graph.getVertexes()) { vertexesNode.add(json(mapper, vertex.deviceId(), 2, vertex.deviceId().uri().getSchemeSpecificPart(), deviceService.isAvailable(vertex.deviceId()))); } // Now scan all links and count number of them between the same devices // using a normalized link key. Map<String, AggLink> linkRecords = aggregateLinks(); // Now build all interior edges using the aggregated links. ArrayNode edgesNode = mapper.createArrayNode(); for (AggLink lr : linkRecords.values()) { edgesNode.add(json(mapper, lr.links.size(), lr.link.src(), lr.link.dst())); } // Merge the exterior and interior vertexes and inject host links as // the exterior edges. for (Host host : hostService.getHosts()) { Set<IpAddress> ipAddresses = host.ipAddresses(); IpAddress ipAddress = ipAddresses.isEmpty() ? null : ipAddresses.iterator().next(); String label = ipAddress != null ? ipAddress.toString() : host.mac().toString(); vertexesNode.add(json(mapper, host.id(), 3, label, true)); edgesNode.add(json(mapper, 1, host.location(), new ConnectPoint(host.id(), portNumber(-1)))); } // Now put the vertexes and edges into a root node and ship them off ObjectNode rootNode = mapper.createObjectNode(); rootNode.set("vertexes", vertexesNode); rootNode.set("edges", edgesNode); return Response.ok(rootNode.toString()).build(); }
From source file:com.rusticisoftware.tincan.ContextActivities.java
@Override public ObjectNode toJSONNode(TCAPIVersion version) { ObjectMapper mapper = Mapper.getInstance(); ObjectNode node = mapper.createObjectNode(); if (this.parent != null && this.parent.size() > 0) { if (version.equals(TCAPIVersion.V095) && this.getParent().size() > 1) { throw new IncompatibleTCAPIVersion("Version " + TCAPIVersion.V095.toString() + " doesn't support lists of activities (parent)"); }/*from ww w. j a va2s.c o m*/ if (version.equals(TCAPIVersion.V095)) { node.put("parent", this.getParent().get(0).toJSONNode(version)); } else { ArrayNode parent = mapper.createArrayNode(); node.put("parent", parent); for (Activity element : this.getParent()) { parent.add(element.toJSONNode(version)); } } } if (this.grouping != null && this.grouping.size() > 0) { if (version.equals(TCAPIVersion.V095) && this.getGrouping().size() > 1) { throw new IncompatibleTCAPIVersion("Version " + TCAPIVersion.V095.toString() + " doesn't support lists of activities (grouping)"); } if (version.equals(TCAPIVersion.V095)) { node.put("grouping", this.getGrouping().get(0).toJSONNode(version)); } else { ArrayNode grouping = mapper.createArrayNode(); node.put("grouping", grouping); for (Activity element : this.getGrouping()) { grouping.add(element.toJSONNode(version)); } } } if (this.other != null && this.other.size() > 0) { if (version.equals(TCAPIVersion.V095) && this.getOther().size() > 1) { throw new IncompatibleTCAPIVersion( "Version " + TCAPIVersion.V095.toString() + " doesn't support lists of activities (other)"); } if (version.equals(TCAPIVersion.V095)) { node.put("other", this.getGrouping().get(0).toJSONNode(version)); } else { ArrayNode other = mapper.createArrayNode(); node.put("other", other); for (Activity element : this.getOther()) { other.add(element.toJSONNode(version)); } } } if (this.category != null && this.category.size() > 0) { if (version.ordinal() <= TCAPIVersion.V100.ordinal()) { ArrayNode category = mapper.createArrayNode(); node.put("category", category); for (Activity element : this.getCategory()) { category.add(element.toJSONNode(version)); } } else { throw new IncompatibleTCAPIVersion( "Version " + version.toString() + " doesn't support the category context activity"); } } return node; }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static ObjectNode getCollectionNode(String... collections) { ObjectMapper mapper = new ObjectMapper(); ObjectNode mNode = mapper.createObjectNode(); ArrayNode aNode = mapper.createArrayNode(); for (String c : collections) { aNode.add(c);//from w w w .j a v a2 s. c o m } mNode.withArray("collection").addAll(aNode); return mNode; }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static ObjectNode getPermissionNode(String roleName, DocumentMetadataHandle.Capability... cap) { ObjectMapper mapper = new ObjectMapper(); ObjectNode mNode = mapper.createObjectNode(); ArrayNode aNode = mapper.createArrayNode(); for (DocumentMetadataHandle.Capability c : cap) { ObjectNode roleNode = mapper.createObjectNode(); roleNode.put("role-name", roleName); roleNode.put("capability", c.toString().toLowerCase()); aNode.add(roleNode);//from w w w.ja va 2s . com } mNode.withArray("permission").addAll(aNode); return mNode; }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void enableWordLexicon(String dbName) throws Exception { ObjectMapper mapper = new ObjectMapper(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode childArray = mapper.createArrayNode(); childArray.add("http://marklogic.com/collation/"); childNode.putArray("word-lexicon").addAll(childArray); setDatabaseProperties(dbName, "word-lexicons", childNode); }
From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java
public static ObjectNode buildSchemaNode(final ObjectMapper objectMapper, final URI schemaUri, final SchemaLoader schemaLoader, final Set<URI> addedBaseSchemaUris) { final Prototype prototype = schemaLoader.getPrototype(schemaUri); if (prototype == null) { return null; }//from ww w. j a v a2 s . c o m final ObjectNode schemaNode = objectMapper.createObjectNode(); schemaNode.put(PropertyName.localName.name(), prototype.getUniqueName().getLocalName()); schemaNode.put(PropertyName.title.name(), prototype.getTitle()); schemaNode.put(PropertyName.uri.name(), schemaUri.toString()); schemaNode.put(PropertyName.version.name(), prototype.getVersion()); String titleSlotName = prototype.getTitleSlotName(); if (StringUtils.isNotBlank(titleSlotName)) { schemaNode.put(PropertyName.titleSlotName.name(), titleSlotName); } else { titleSlotName = getTitleSlotName(schemaUri, schemaLoader); if (StringUtils.isNotBlank(titleSlotName)) { schemaNode.put(PropertyName.titleSlotName.name(), titleSlotName); } } final Set<String> allSlotNames = prototype.getAllSlotNames(); if (allSlotNames != null && !allSlotNames.isEmpty()) { final ArrayNode propertyNamesNode = objectMapper.createArrayNode(); for (final String slotName : allSlotNames) { final ProtoSlot protoSlot = prototype.getProtoSlot(slotName); if (protoSlot instanceof LinkProtoSlot) { continue; } if (protoSlot.getDeclaringSchemaUri().equals(schemaUri)) { propertyNamesNode.add(slotName); } } if (propertyNamesNode.size() > 0) { schemaNode.put(PropertyName.propertyNames.name(), propertyNamesNode); } } 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) { schemaNode.put(PropertyName.keyPropertyNames.name(), keyPropertyNamesNode); } } final Set<String> allKeySlotNames = prototype.getAllKeySlotNames(); final ArrayNode allKeySlotNamesNode = objectMapper.createArrayNode(); schemaNode.put(PropertyName.allKeySlotNames.name(), allKeySlotNamesNode); for (final String keySlotName : allKeySlotNames) { allKeySlotNamesNode.add(keySlotName); } 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) { schemaNode.put(PropertyName.comparablePropertyNames.name(), comparablePropertyNamesNode); } } final Map<URI, LinkProtoSlot> linkProtoSlots = prototype.getLinkProtoSlots(); if (linkProtoSlots != null && !linkProtoSlots.isEmpty()) { final ArrayNode linkNamesNode = objectMapper.createArrayNode(); for (final LinkProtoSlot linkProtoSlot : linkProtoSlots.values()) { if (linkProtoSlot.getDeclaringSchemaUri().equals(schemaUri)) { linkNamesNode.add(linkProtoSlot.getName()); } } if (linkNamesNode.size() > 0) { schemaNode.put(PropertyName.linkNames.name(), linkNamesNode); } } final Set<URI> declaredBaseSchemaUris = prototype.getDeclaredBaseSchemaUris(); if (declaredBaseSchemaUris != null && !declaredBaseSchemaUris.isEmpty() && addedBaseSchemaUris != null) { final ArrayNode baseSchemasNode = objectMapper.createArrayNode(); for (final URI baseSchemaUri : declaredBaseSchemaUris) { if (!addedBaseSchemaUris.contains(baseSchemaUri)) { final ObjectNode baseSchemaNode = buildSchemaNode(objectMapper, baseSchemaUri, schemaLoader, addedBaseSchemaUris); baseSchemasNode.add(baseSchemaNode); addedBaseSchemaUris.add(baseSchemaUri); } } if (baseSchemasNode.size() > 0) { schemaNode.put(PropertyName.baseSchemas.name(), baseSchemasNode); } } return schemaNode; }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void includeElementField(String dbName, String field_name, String namespace, String elementName) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode arrNode = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("namespace-uri", namespace); childNodeObject.put("localname", elementName); childNodeObject.put("weight", 1.0); arrNode.add(childNodeObject);// w w w .jav a 2 s. c om childNode.putArray("included-element").addAll(arrNode); // mainNode.put("included-elements", childNode); System.out.println(childNode.toString()); setDatabaseFieldProperties(dbName, field_name, "included-element", childNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addField(String dbName, String fieldName) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode arrNode = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("field-name", fieldName); childNodeObject.put("include-root", true); childNodeObject.putNull("included-elements"); childNodeObject.putNull("excluded-elements"); childNodeObject.putNull("tokenizer-overrides"); arrNode.add(childNodeObject);// w w w. ja v a 2s . com childNode.putArray("field").addAll(arrNode); // mainNode.put("fields", childNode); // System.out.println("Entered field to make it true"); setDatabaseProperties(dbName, "field", childNode); }