List of usage examples for com.fasterxml.jackson.databind.node JsonNodeFactory instance
JsonNodeFactory instance
To view the source code for com.fasterxml.jackson.databind.node JsonNodeFactory instance.
Click Source Link
From source file:models.protocol.v1.MetricMessagesProcessor.java
private void processMetricsList(final MetricsList metricsList) { //TODO(barp): Map with a POJO mapper [MAI-184] final ObjectNode dataNode = JsonNodeFactory.instance.objectNode(); final ArrayNode services = JsonNodeFactory.instance.arrayNode(); for (final Map.Entry<String, Map<String, Set<String>>> service : metricsList.getMetrics().entrySet()) { final ObjectNode serviceObject = JsonNodeFactory.instance.objectNode(); serviceObject.put("name", service.getKey()); final ArrayNode metrics = JsonNodeFactory.instance.arrayNode(); for (final Map.Entry<String, Set<String>> metric : service.getValue().entrySet()) { final ObjectNode metricObject = JsonNodeFactory.instance.objectNode(); metricObject.put("name", metric.getKey()); final ArrayNode stats = JsonNodeFactory.instance.arrayNode(); for (final String statistic : metric.getValue()) { final ObjectNode statsObject = JsonNodeFactory.instance.objectNode(); statsObject.put("name", statistic); statsObject.set("children", JsonNodeFactory.instance.arrayNode()); stats.add(statsObject);// w w w . j a v a 2 s.c o m } metricObject.set("children", stats); metrics.add(metricObject); } serviceObject.set("children", metrics); services.add(serviceObject); } dataNode.set("metrics", services); _connectionContext.sendCommand(COMMAND_METRICS_LIST, dataNode); }
From source file:com.turn.shapeshifter.NamedSchemaParserTest.java
@Test public void testParseWithEmptyRepeated() throws Exception { NamedSchema schema = NamedSchema.of(Union.getDescriptor(), "Union").useSchema("union_repeated", "Union"); SchemaRegistry registry = new SchemaRegistry(); registry.register(schema);//from w w w .ja v a 2 s . co m Union union = Union.newBuilder().setBoolValue(true).addUnionRepeated(Union.getDefaultInstance()).build(); ObjectNode result = (ObjectNode) new NamedSchemaSerializer(schema).serialize(union, registry); result.put("unionRepeated", new ArrayNode(JsonNodeFactory.instance)); Union parsed = Union.newBuilder().mergeFrom(new NamedSchemaParser(schema).parse(result, registry)).build(); Assert.assertTrue(parsed.getBoolValue()); Assert.assertEquals(0, parsed.getUnionRepeatedCount()); }
From source file:io.gs2.realtime.Gs2RealtimeClient.java
/** * ???<br>// w ww. j av a 2 s . com * <br> * * @param request * @return ? */ public UpdateGatheringPoolResult updateGatheringPool(UpdateGatheringPoolRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode(); if (request.getDescription() != null) body.put("description", request.getDescription()); HttpPut put = createHttpPut(Gs2Constant.ENDPOINT_HOST + "/gatheringPool/" + (request.getGatheringPoolName() == null || request.getGatheringPoolName().equals("") ? "null" : request.getGatheringPoolName()) + "", credential, ENDPOINT, UpdateGatheringPoolRequest.Constant.MODULE, UpdateGatheringPoolRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { put.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } return doRequest(put, UpdateGatheringPoolResult.class); }
From source file:uk.ac.gate.cloud.data.DataBundle.java
/** * Close a bundle that is open for uploads. *//*w w w.j a v a2 s .co m*/ public void close() { // has to be a POST request, but any body will do client.postForUpdate(url + "/close", this, JsonNodeFactory.instance.objectNode()); }
From source file:org.apache.streams.elasticsearch.processor.PercolateTagProcessor.java
@Override public List<StreamsDatum> process(StreamsDatum entry) { List<StreamsDatum> result = Lists.newArrayList(); String json;/* www .j a v a 2 s .c om*/ ObjectNode node; // first check for valid json if (entry.getDocument() instanceof String) { json = (String) entry.getDocument(); try { node = (ObjectNode) mapper.readTree(json); } catch (IOException e) { e.printStackTrace(); return null; } } else if (entry.getDocument() instanceof ObjectNode) { node = (ObjectNode) entry.getDocument(); try { json = mapper.writeValueAsString(node); } catch (JsonProcessingException e) { LOGGER.warn("Invalid datum: ", node); return null; } } else { LOGGER.warn("Incompatible document type: ", entry.getDocument().getClass()); return null; } StringBuilder percolateRequestJson = new StringBuilder(); percolateRequestJson.append("{ \"doc\": "); percolateRequestJson.append(json); //percolateRequestJson.append("{ \"content\" : \"crazy good shit\" }"); percolateRequestJson.append("}"); PercolateRequestBuilder request; PercolateResponse response; try { LOGGER.trace("Percolate request json: {}", percolateRequestJson.toString()); request = manager.getClient().preparePercolate().setIndices(config.getIndex()) .setDocumentType(config.getType()).setSource(percolateRequestJson.toString()); LOGGER.trace("Percolate request: {}", mapper.writeValueAsString(request.request())); response = request.execute().actionGet(); LOGGER.trace("Percolate response: {} matches", response.getMatches().length); } catch (Exception e) { LOGGER.warn("Percolate exception: {}", e.getMessage()); return null; } ArrayNode tagArray = JsonNodeFactory.instance.arrayNode(); Iterator<PercolateResponse.Match> matchIterator = response.iterator(); while (matchIterator.hasNext()) { tagArray.add(matchIterator.next().getId().string()); } LOGGER.trace("Percolate matches: {}", tagArray); Activity activity = mapper.convertValue(node, Activity.class); appendMatches(tagArray, activity); entry.setDocument(activity); result.add(entry); return result; }
From source file:io.wcm.caravan.pipeline.extensions.hal.crawler.HalCrawlerTest.java
@Test public void shouldNotCrashWithExceptionHandler() { crawler = new HalCrawler(client, LinkExtractors.all(), UriParametersProviders.empty(), OutputProcessors.report(), StopCriteria.alwaysEnabled()); // add Not Found Link to HAL Entry Point resourceLink1.addLinks("item", new Link("/not-found")); pipelineCtx.getCaravanHttpClient().getRequestMatchers().get(1) .response(resourceLink1.getModel().toString()); // mock Not Found request pipelineCtx.getCaravanHttpClient().mockRequest().url("/not-found") .response(new CaravanHttpResponseBuilder().status(404).reason("Not Found").build()); client.addExceptionHandler(new JsonPipelineExceptionHandler() { @Override//from ww w .jav a2s . c om public Observable<JsonPipelineOutput> call(JsonPipelineOutput defaultFallbackContent, RuntimeException caughtException) { return Observable.just(defaultFallbackContent .withPayload(JsonNodeFactory.instance.textNode(caughtException.getMessage()))); } }); JsonPipelineOutput output = pipeline.applyAction(crawler).getOutput().toBlocking().single(); HalResource hal = new HalResource(output.getPayload()); assertEquals(6, hal.getLinks().size()); }
From source file:io.syndesis.maven.ExtractConnectorDescriptorsMojo.java
private ObjectNode getComponentMeta(ClassLoader classLoader) { Properties properties = loadComponentProperties(classLoader); if (properties == null) { return null; }//from w ww. j a v a2 s.co 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.eel.kitchen.jsonschema.report.ValidationReport.java
/** * Retrieve all messages as a JSON object * * <p>The retrieved JSON document is an object where:</p> * * <ul>/* w w w.jav a 2 s. c o m*/ * <li>keys are string representations of {@link JsonPointer}s,</li> * <li>values are arrays of objects where each individual object is the * JSON representation of one message.</li> * </ul> * * <p>Note: the returned {@link JsonNode} is mutable.</p> * * @see Message#toJsonNode() * * @return a JSON object with all validation messages */ public JsonNode asJsonObject() { final ObjectNode ret = JsonNodeFactory.instance.objectNode(); ArrayNode node; List<Message> messages; for (final JsonPointer ptr : msgMap.keySet()) { node = JsonNodeFactory.instance.arrayNode(); messages = MESSAGE_ORDER.sortedCopy(msgMap.get(ptr)); for (final Message message : messages) node.add(message.toJsonNode()); ret.put(ptr.toString(), node); } return ret; }
From source file:com.opentok.util.HttpClient.java
public String startArchive(String sessionId, ArchiveProperties properties) throws OpenTokException { String responseString = null; Future<Response> request = null; String requestBody = null;//from w w w. java 2 s . co m // TODO: maybe use a StringBuilder? String url = this.apiUrl + "/v2/partner/" + this.apiKey + "/archive"; JsonNodeFactory nodeFactory = JsonNodeFactory.instance; ObjectNode requestJson = nodeFactory.objectNode(); requestJson.put("sessionId", sessionId); requestJson.put("hasVideo", properties.hasVideo()); requestJson.put("hasAudio", properties.hasAudio()); requestJson.put("outputMode", properties.outputMode().toString()); if (properties.name() != null) { requestJson.put("name", properties.name()); } try { requestBody = new ObjectMapper().writeValueAsString(requestJson); } catch (JsonProcessingException e) { throw new OpenTokException("Could not start an OpenTok Archive. The JSON body encoding failed.", e); } try { request = this.preparePost(url).setBody(requestBody).setHeader("Content-Type", "application/json") .execute(); } catch (IOException e) { throw new RequestException("Could not start an OpenTok Archive.", e); } try { Response response = request.get(); switch (response.getStatusCode()) { case 200: responseString = response.getResponseBody(); break; case 403: throw new RequestException("Could not start an OpenTok Archive. The request was not authorized."); case 404: throw new RequestException("Could not start an OpenTok Archive. The sessionId does not exist. " + "sessionId = " + sessionId); case 409: throw new RequestException("Could not start an OpenTok Archive. The session is either " + "peer-to-peer or already recording. sessionId = " + sessionId); case 500: throw new RequestException("Could not start an OpenTok Archive. A server error occurred."); default: throw new RequestException("Could not start an OpenTok Archive. The server response was invalid." + " response code: " + response.getStatusCode()); } // if we only wanted Java 7 and above, we could DRY this into one catch clause } catch (InterruptedException e) { throw new RequestException("Could not start an OpenTok Archive.", e); } catch (ExecutionException e) { throw new RequestException("Could not start an OpenTok Archive.", e); } catch (IOException e) { throw new RequestException("Could not start an OpenTok Archive.", e); } return responseString; }
From source file:com.arpnetworking.metrics.proxy.actors.Connection.java
/** * Sends a command object to the connected client. * * @param command The command./* w w w.j a v a 2s . co m*/ * @param data The data for the command. */ public void sendCommand(final String command, final ObjectNode data) { final ObjectNode message = JsonNodeFactory.instance.objectNode(); message.put("command", command); message.set("data", data); send(message); }