List of usage examples for com.fasterxml.jackson.databind.node ObjectNode size
public int size()
From source file:com.google.api.server.spi.EndpointsServletTest.java
@Test public void methodOverride() throws IOException { req.setRequestURI("/_ah/api/test/v2/increment"); req.setMethod("POST"); req.addHeader("X-HTTP-Method-Override", "PATCH"); req.setParameter("x", "1"); servlet.service(req, resp);//from ww w.j a v a2 s. c o m assertThat(resp.getStatus()).isEqualTo(HttpServletResponse.SC_OK); ObjectMapper mapper = ObjectMapperUtil.createStandardObjectMapper(); ObjectNode actual = mapper.readValue(resp.getContentAsString(), ObjectNode.class); assertThat(actual.size()).isEqualTo(1); assertThat(actual.get("x").asInt()).isEqualTo(2); }
From source file:de.thingweb.servient.MultiThingTests.java
@Test public void multiThingServient() throws Exception { int nthings = 10; Thing[] things = new Thing[nthings]; Action testAction = Action.getBuilder("testAction").build(); Property testProp = Property.getBuilder("testProp").setWriteable(true).setValueType("xsd:string").build(); for (int i = 0; i < nthings; i++) { things[i] = new Thing("thing" + i); things[i].addAction(testAction); things[i].addProperty(testProp); server.addThing(things[i]);/*from w w w.j av a2 s .c o m*/ } ServientBuilder.start(); JsonNode jsonNode = jsonMapper.readTree(new URL("http://localhost:8080/things/")); assertThat("should be an object", jsonNode.isObject(), is(true)); final ObjectNode repo = (ObjectNode) jsonNode; assertThat("expected at least the same number of links under /things as things", repo.size(), greaterThanOrEqualTo(nthings)); Arrays.stream(things).forEach(thing -> assertThat("should contain all things, misses " + thing.getName(), repo.get(thing.getName()), notNullValue())); //further checks }
From source file:io.macgyver.neorx.rest.NeoRxClientTest.java
@Test public void testParams() { NeoRxClient c = new NeoRxClient(); ObjectNode n = c.createParameters("abc", "def", "xxx", "yyy"); org.junit.Assert.assertEquals(2, n.size()); Assert.assertEquals(0, c.createParameters().size()); Assert.assertEquals("def", c.createParameters("abc", "def").path("abc").asText()); }
From source file:com.turn.shapeshifter.NamedSchemaSerializer.java
/** * {@inheritDoc}//from www .j ava 2 s . c om * * This variation allows for the inclusion of schemas for serializing * sub-objects that may appear in {@code message}. If no suitable schema * is found in the registry, a schema with default settings is generated * on the fly using {@link * SchemaSource#get(com.google.protobuf.Descriptors.Descriptor)}. * */ @Override public JsonNode serialize(Message message, ReadableSchemaRegistry registry) throws SerializationException { ObjectNode object = new ObjectNode(JsonNodeFactory.instance); for (Map.Entry<String, String> constant : schema.getConstants().entrySet()) { object.put(constant.getKey(), constant.getValue()); } for (Map.Entry<String, FieldDescriptor> fieldEntry : schema.getFields().entrySet()) { if (schema.getSkippedFields().contains(fieldEntry.getKey())) { continue; } FieldDescriptor field = fieldEntry.getValue(); if (field.isRepeated()) { int count = message.getRepeatedFieldCount(field); if (count > 0) { if (schema.getMappings().containsKey(field.getName())) { ObjectNode objectNode = serializeMappedField(message, registry, field, count); if (objectNode.size() > 0) { object.put(schema.getPropertyName(field.getName()), objectNode); } } else { ArrayNode array = serializeRepeatedField(message, registry, field, count); if (array.size() > 0) { object.put(schema.getPropertyName(field.getName()), array); } } } } else if (message.hasField(field)) { Object value = message.getField(field); JsonNode fieldNode = serializeValue(value, field, registry); object.put(schema.getPropertyName(field.getName()), fieldNode); } } if (object.size() == 0) { return NullNode.instance; } return object; }
From source file:org.modeshape.web.jcr.rest.handler.RestItemHandlerImpl.java
/** * Performs a bulk creation of items, using a single {@link javax.jcr.Session}. If any of the items cannot be created for whatever * reason, the entire operation fails.//from ww w . j ava 2s .co m * * @param request the servlet request; may not be null or unauthenticated * @param repositoryName the URL-encoded repository name * @param workspaceName the URL-encoded workspace name * @param requestContent the JSON-encoded representation of the nodes and, possibly, properties to be added * @return a {@code non-null} {@link Result} * @throws javax.jcr.RepositoryException if any of the JCR operations fail * @see RestItemHandlerImpl#addItem(Request, String, String, String, String) */ @Override public void addItems(Request request, String repositoryName, String workspaceName, String requestContent) throws RepositoryException { ObjectNode requestBody = stringToJSONObject(requestContent); if (requestBody.size() != 0) { Session session = getSession(request, repositoryName, workspaceName); TreeMap<String, JsonNode> nodesByPath = createNodesByPathMap(requestBody); addMultipleNodes(request, nodesByPath, session); } }
From source file:org.modeshape.web.jcr.rest.handler.RestItemHandlerImpl.java
/** * Performs a bulk updating of items, using a single {@link javax.jcr.Session}. If any of the items cannot be updated for whatever * reason, the entire operation fails./* w w w .j av a 2 s . c o m*/ * * @param request the servlet request; may not be null or unauthenticated * @param repositoryName the URL-encoded repository name * @param workspaceName the URL-encoded workspace name * @param requestContent the JSON-encoded representation of the values and, possibly, properties to be set * @throws javax.jcr.RepositoryException if any of the JCR operations fail * @see RestItemHandlerImpl#updateItem(Request, String, String, String, String) */ @Override public void updateItems(Request request, String repositoryName, String workspaceName, String requestContent) throws RepositoryException { ObjectNode requestBody = stringToJSONObject(requestContent); if (requestBody.size() != 0) { Session session = getSession(request, repositoryName, workspaceName); TreeMap<String, JsonNode> nodesByPath = createNodesByPathMap(requestBody); updateMultipleNodes(request, session, nodesByPath); } }
From source file:com.almende.eve.capabilities.Config.java
private Config(final ObjectNode node) { super(JOM.getInstance().getNodeFactory(), new LinkedHashMap<String, JsonNode>(node != null ? node.size() : 2)); if (node != null) { this.setAll(node); }//from w w w . jav a 2 s. c o m }
From source file:org.apache.taverna.scufl2.translator.t2flow.TestDispatchLayerParsing.java
@Test public void whichLayers() throws Exception { Processor parallelise = processors.getByName("retries"); // As inspected in /scufl2-t2flow/src/test/resources/dispatchlayers-xsd.t2flow // List<String> expectedNames = Arrays.asList(PARALLELIZE, ERRORBOUNCE, FAILOVER, RETRY, INVOKE); // NOTE: Only those with configuration are present List<String> expectedNames = Arrays.asList(RETRY); Configuration config = scufl2Tools.configurationFor(parallelise, profile); ObjectNode json = config.getJsonAsObjectNode(); for (String name : expectedNames) { assertTrue("Could not find config for dispatch layer " + name, json.has(name)); }/*from w w w .j a v a2s .c om*/ assertEquals("Additional dispatch layer configurations found", expectedNames.size(), json.size()); }
From source file:io.syndesis.maven.ExtractConnectorDescriptorsMojo.java
@Override @SuppressWarnings("PMD.EmptyCatchBlock") public void execute() throws MojoExecutionException, MojoFailureException { ArrayNode root = new ArrayNode(JsonNodeFactory.instance); URLClassLoader classLoader = null; try {//from w w w . j a va 2s . c om 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) { } } } }
From source file:io.syndesis.maven.ExtractConnectorDescriptorsMojo.java
private void addConnectorMeta(ObjectNode root, ClassLoader classLoader) { ObjectNode node = new ObjectNode(JsonNodeFactory.instance); addOptionalNode(classLoader, node, "meta", "camel-connector.json"); addOptionalSchemaAsString(classLoader, node, "schema", "camel-connector-schema.json"); if (node.size() > 0) { root.set("connector", node); }/* w w w . j a v a 2 s .c om*/ }