List of usage examples for com.fasterxml.jackson.databind ObjectMapper createObjectNode
@Override
public ObjectNode createObjectNode()
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:com.netflix.genie.server.resources.JobResource.java
/** * Get job status for give job id./*from w w w. j a v a 2 s. co m*/ * * @param id id for job to look up * @return The status of the job * @throws GenieException For any error */ @GET @Path("/{id}/status") @ApiOperation(value = "Get the status of the job ", notes = "Get the status of job whose id is sent", response = String.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Job not found"), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid id supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public ObjectNode getJobStatus( @ApiParam(value = "Id of the job.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called for job id:" + id); final ObjectMapper mapper = new ObjectMapper(); final ObjectNode node = mapper.createObjectNode(); node.put("status", this.jobService.getJobStatus(id).toString()); return node; }
From source file:io.cslinmiso.line.model.LineBase.java
/** * Send image.//from w w w . j av a2 s .c o m * * @param is the is * @return true, if successful * @throws Exception the exception */ public boolean sendImage(InputStream is) throws Exception { try { LineMessage message = new LineMessage(); message.setTo(getId()); message.setText(""); message.setContentType(ContentType.IMAGE); Message sendMessage = client.sendMessage(0, message); String messageId = sendMessage.getId(); // preparing params which is detail of image to upload server ObjectMapper objectMapper = new ObjectMapper(); ObjectNode objectNode = objectMapper.createObjectNode(); objectNode.put("name", "media"); objectNode.put("oid", messageId); objectNode.put("size", is.available()); objectNode.put("type", "image"); objectNode.put("ver", "1.0"); Map<String, Object> data = new HashMap<String, Object>(); // data.put("file", file); data.put("params", objectMapper.writeValueAsString(objectNode)); String url = LineApi.LINE_UPLOADING_URL; LineApiImpl api = (LineApiImpl) client.getApi(); boolean isUploaded = api.postContent(url, data, is); if (isUploaded == false) { throw new Exception("Fail to upload image."); } return true; } catch (Exception e) { throw e; } }
From source file:io.cslinmiso.line.model.LineBase.java
public boolean sendFile(String name, InputStream is) throws Exception { String fileName = "SendByLineAPI4J"; String fileSize = String.valueOf(is.available()); try {/*ww w.j a v a 2 s.co m*/ if (StringUtils.isNotEmpty(name)) { fileName = name; } LineMessage message = new LineMessage(); message.setTo(getId()); message.setContentType(ContentType.FILE); Map<String, String> contentMetadata = new HashMap<String, String>(); contentMetadata.put("FILE_NAME", fileName); contentMetadata.put("FILE_SIZE", fileSize); message.setContentMetadata(contentMetadata); Message sendMessage = client.sendMessage(0, message); String messageId = sendMessage.getId(); // preparing params which is detail of image to upload server ObjectMapper objectMapper = new ObjectMapper(); ObjectNode objectNode = objectMapper.createObjectNode(); objectNode.put("name", fileName); objectNode.put("oid", messageId); objectNode.put("size", fileSize); objectNode.put("type", "file"); objectNode.put("ver", "1.0"); Map<String, Object> data = new HashMap<String, Object>(); data.put("params", objectMapper.writeValueAsString(objectNode)); String url = LineApi.LINE_UPLOADING_URL; LineApiImpl api = (LineApiImpl) client.getApi(); boolean isUploaded = api.postContent(url, data, is); if (isUploaded == false) { throw new Exception("Fail to upload file."); } return true; } catch (Exception e) { throw e; } }
From source file:com.msopentech.odatajclient.testservice.utils.JSONUtilities.java
@Override public InputStream readEntities(final List<String> links, final String linkName, final String next, final boolean forceFeed) throws Exception { if (links.isEmpty()) { throw new NotFoundException(); }/*from ww w .j av a 2s . com*/ final ObjectMapper mapper = new ObjectMapper(); final ObjectNode node = mapper.createObjectNode(); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); if (forceFeed || links.size() > 1) { bos.write("[".getBytes()); } for (String link : links) { try { final Map.Entry<String, String> uri = Commons.parseEntityURI(link); final Map.Entry<String, InputStream> entity = readEntity(uri.getKey(), uri.getValue(), Accept.JSON_FULLMETA); if (bos.size() > 1) { bos.write(",".getBytes()); } IOUtils.copy(entity.getValue(), bos); } catch (Exception e) { // log and ignore link LOG.warn("Error parsing uri {}", link, e); } } if (forceFeed || links.size() > 1) { bos.write("]".getBytes()); } node.set(JSON_VALUE_NAME, mapper.readTree(new ByteArrayInputStream(bos.toByteArray()))); if (StringUtils.isNotBlank(next)) { node.set(JSON_NEXTLINK_NAME, new TextNode(next)); } return IOUtils.toInputStream(node.toString()); }
From source file:org.onosproject.cordmcast.CordMcast.java
private void addRemoteRoute(McastRoute route, ConnectPoint inPort) { checkNotNull(route);/* w w w. j av a2s .c om*/ if (syncHost == null) { log.warn("No host configured for synchronization; route will be dropped"); return; } Optional<AccessAgentData> accessAgent = cordConfigService.getAccessAgent(inPort.deviceId()); if (!accessAgent.isPresent()) { log.warn("No accessAgent config found for in port {}", inPort); return; } if (!accessAgent.get().getOltConnectPoint(inPort).isPresent()) { log.warn("No OLT configured for in port {}", inPort); return; } ConnectPoint oltConnectPoint = accessAgent.get().getOltConnectPoint(inPort).get(); log.debug("Sending route {} to other ONOS {}", route, fabricOnosUrl); Invocation.Builder builder = getClientBuilder(fabricOnosUrl); ObjectNode json = codecService.getCodec(McastRoute.class).encode(route, new AbstractWebResource()); try { builder.post(Entity.json(json.toString())); builder = getClientBuilder(fabricOnosUrl + "/sinks/" + route.group() + "/" + route.source()); ObjectMapper mapper = new ObjectMapper(); ObjectNode obj = mapper.createObjectNode(); obj.putArray("sinks").add(oltConnectPoint.deviceId() + "/" + oltConnectPoint.port()); builder.post(Entity.json(obj.toString())); } catch (ProcessingException e) { log.warn("Unable to send route to remote controller: {}", e.getMessage()); } }
From source file:com.gsma.mobileconnect.cache.DiscoveryCacheHashMapImplTest.java
@Test public void get_withExpiredTtl_shouldReturnNull() { // GIVEN/*from w ww . ja va 2 s . c o m*/ ObjectMapper objectMapper = new ObjectMapper(); DiscoveryCacheKey key = DiscoveryCacheKey.newWithDetails("a", "a"); IDiscoveryCache cache = Factory.getDefaultDiscoveryCache(); DiscoveryCacheValue value = new DiscoveryCacheValue(new Date(Long.MIN_VALUE), objectMapper.createObjectNode()); // WHEN cache.add(key, value); boolean cacheIsEmptyAfterAdd = cache.isEmpty(); DiscoveryCacheValue cachedValue = cache.get(key); boolean cacheIsEmptyAfterGet = cache.isEmpty(); // THEN assertFalse(cacheIsEmptyAfterAdd); assertNull(cachedValue); assertTrue(cacheIsEmptyAfterGet); }
From source file:org.pf9.pangu.app.act.rest.diagram.services.BaseProcessDefinitionDiagramLayoutResource.java
private JsonNode getProcessDefinitionResponse(ProcessDefinitionEntity processDefinition) { ObjectMapper mapper = new ObjectMapper(); ObjectNode pdrJSON = mapper.createObjectNode(); pdrJSON.put("id", processDefinition.getId()); pdrJSON.put("name", processDefinition.getName()); pdrJSON.put("key", processDefinition.getKey()); pdrJSON.put("version", processDefinition.getVersion()); pdrJSON.put("deploymentId", processDefinition.getDeploymentId()); pdrJSON.put("isGraphicNotationDefined", isGraphicNotationDefined(processDefinition)); return pdrJSON; }
From source file:org.fcrepo.camel.indexing.solr.SolrDeleteProcessor.java
/** * Format a message so that a record can be deleted in Solr. * * The output format should be:/*from w w w . j ava 2 s .c o m*/ * * { * "delete" : { * "id" : "/foo" * }, * "commitWithin" : 500 * } * * @param exchange The incoming message exchange. */ public void process(final Exchange exchange) throws Exception { final Message in = exchange.getIn(); final ObjectMapper mapper = new ObjectMapper(); if (isBlank(in.getHeader(FcrepoHeaders.FCREPO_IDENTIFIER, String.class))) { in.setHeader(FcrepoHeaders.FCREPO_IDENTIFIER, in.getHeader(JmsHeaders.IDENTIFIER, String.class)); } if (isBlank(in.getHeader(FcrepoHeaders.FCREPO_BASE_URL, String.class))) { in.setHeader(FcrepoHeaders.FCREPO_BASE_URL, in.getHeader(JmsHeaders.BASE_URL, String.class)); } final ObjectNode root = mapper.createObjectNode(); root.putObject("delete").put("id", in.getHeader(FcrepoHeaders.FCREPO_BASE_URL, String.class) + in.getHeader(FcrepoHeaders.FCREPO_IDENTIFIER, String.class)); in.setBody(mapper.writeValueAsString(root)); in.setHeader(Exchange.CONTENT_TYPE, "application/json"); in.setHeader(Exchange.HTTP_METHOD, "POST"); }
From source file:com.google.api.server.spi.config.jsonwriter.JsonConfigWriterTest.java
@Test public void testBeanPropertyDateType() throws Exception { ObjectMapper mapper = new ObjectMapper(); ObjectNode schemasConfig = mapper.createObjectNode(); writer.addTypeToSchema(schemasConfig, TypeToken.of(Bean.class), apiConfig, null); JsonNode beanConfig = schemasConfig.path("Bean"); assertEquals("Bean", beanConfig.path("id").asText()); assertEquals("object", beanConfig.path("type").asText()); assertEquals("string", beanConfig.path("properties").path("date").path("type").asText()); assertEquals("date-time", beanConfig.path("properties").path("date").path("format").asText()); }
From source file:com.google.api.server.spi.config.jsonwriter.JsonConfigWriterTest.java
@Test public void testEnumType() throws Exception { ObjectMapper mapper = new ObjectMapper(); ObjectNode schemasConfig = mapper.createObjectNode(); writer.addTypeToSchema(schemasConfig, TypeToken.of(Outcome.class), apiConfig, null); JsonNode outcome = schemasConfig.path("Outcome"); assertEquals("Outcome", outcome.path("id").asText()); assertEquals("string", outcome.path("type").asText()); JsonNode enumConfig = outcome.path("enum"); assertTrue(enumConfig.isArray());/*from w ww .jav a2 s .c o m*/ assertEquals(3, enumConfig.size()); assertEquals(Outcome.WON.toString(), enumConfig.get(0).asText()); assertEquals(Outcome.LOST.toString(), enumConfig.get(1).asText()); assertEquals(Outcome.TIE.toString(), enumConfig.get(2).asText()); }