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:com.redhat.lightblue.hook.audit.AuditHookTest.java
/** * Very simple (and hacky) test of document processing. * * @throws Exception/*from ww w. ja v a 2 s . c o m*/ */ @Test public void updateWithId() throws Exception { // verify up front there is nothing in audit collection DBCollection auditColl = mongo.getDB().createCollection("audit", null); Assert.assertEquals(0, auditColl.find().count()); // parse audit and foo metadata EntityMetadata auditMetadata = parser.parseEntityMetadata(json(FileUtil.readFile(AUDIT_METADATA_FILENAME))); EntityMetadata fooMetadata = parser.parseEntityMetadata(json(FileUtil.readFile(FOO_METADATA_FILENAME))); // create audit hook configuration AuditHookConfiguration config = new AuditHookConfiguration("foo", "0.1.0-SNAPSHOT"); // ------------------------------------------------------------ // mock up document data List<HookDoc> processedDocuments = new ArrayList<>(); // need a json node for pre and post data. will create together to make easier ObjectNode pre = new ObjectNode(JsonNodeFactory.instance); ObjectNode post = new ObjectNode(JsonNodeFactory.instance); // only set _id on post, assumes the update input doesn't have the _id post.put("_id", "ID"); // will have a field "foo" on each with different values pre.put("foo", "old"); post.put("foo", "new"); // and field "bar" with same values pre.put("bar", "same"); post.put("bar", "same"); // important, metadata on hook doc is the entity metadata (foo), not audit metadata HookDoc hd = new HookDoc(fooMetadata, new JsonDoc(pre), new JsonDoc(post), CRUDOperation.UPDATE); processedDocuments.add(hd); // ------------------------------------------------------------ // create hook AuditHook hook = new AuditHook(); // process hook hook.processHook(auditMetadata, config, processedDocuments); // verify there's one audit in database // verify up front there is nothing in audit collection Assert.assertEquals(1, auditColl.find().count()); }
From source file:org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverterTest.java
@Test public void testNoTypeSupplied() throws Exception { this.expectedException.expect(MessageConversionException.class); this.expectedException.expectMessage("does not contain a Type attribute"); ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Message", "Hello World!"); String payload = jsonObject.toString(); new NotificationRequestConverter().fromMessage(MessageBuilder.withPayload(payload).build(), null); }
From source file:io.confluent.connect.elasticsearch.Mapping.java
/** * Infer mapping from the provided schema. * @param schema The schema used to infer mapping. */// w w w. j av a 2 s. com public static JsonNode inferMapping(Schema schema) { if (schema == null) { throw new DataException("Cannot infer mapping without schema."); } // Handle logical types String schemaName = schema.name(); Object defaultValue = schema.defaultValue(); if (schemaName != null) { switch (schemaName) { case Date.LOGICAL_NAME: case Time.LOGICAL_NAME: case Timestamp.LOGICAL_NAME: return inferPrimitive(ElasticsearchSinkConnectorConstants.DATE_TYPE, defaultValue); case Decimal.LOGICAL_NAME: return inferPrimitive(ElasticsearchSinkConnectorConstants.DOUBLE_TYPE, defaultValue); } } Schema keySchema; Schema valueSchema; Schema.Type schemaType = schema.type(); ObjectNode properties = JsonNodeFactory.instance.objectNode(); ObjectNode fields = JsonNodeFactory.instance.objectNode(); switch (schemaType) { case ARRAY: valueSchema = schema.valueSchema(); return inferMapping(valueSchema); case MAP: keySchema = schema.keySchema(); valueSchema = schema.valueSchema(); properties.set("properties", fields); fields.set(MAP_KEY, inferMapping(keySchema)); fields.set(MAP_VALUE, inferMapping(valueSchema)); return properties; case STRUCT: properties.set("properties", fields); for (Field field : schema.fields()) { String fieldName = field.name(); Schema fieldSchema = field.schema(); fields.set(fieldName, inferMapping(fieldSchema)); } return properties; default: return inferPrimitive(ElasticsearchSinkConnectorConstants.TYPES.get(schemaType), defaultValue); } }
From source file:easyrpc.server.serialization.jsonrpc.JSONCallee.java
@Override public byte[] matchMethod(Object object, byte[] callInfo) { try {/*from w w w . j ava 2 s . com*/ Object returnedObject = null; ObjectNode call = (ObjectNode) MAPPER.readTree(callInfo); String jsonrpc = call.get("jsonrpc").textValue(); if (jsonrpc == null || !"2.0".equals(jsonrpc)) { throw new SerializationException( "'jsonrpc' value must be '2.0' and actually is: '" + jsonrpc + "'"); } String methodName = call.get("method").textValue(); if (methodName == null) throw new SerializationException("The 'method' field must not be null: " + call.toString()); Class iface = object.getClass(); for (Method m : iface.getMethods()) { if (methodName.equals(m.getName())) { ArrayNode jsParams = (ArrayNode) call.get("params"); if (jsParams == null || jsParams.size() == 0) { try { returnedObject = m.invoke(object); // System.out.println("returnedObject = " + returnedObject); } catch (Exception e) { e.printStackTrace(); return returnJsonRpcError(call.get("id"), e); } } else { // System.out.println("methodName = " + methodName); Object[] params = new Object[jsParams.size()]; for (int i = 0; i < params.length; i++) { params[i] = MAPPER.convertValue(jsParams.get(i), m.getParameters()[i].getType()); // System.out.println("params[i] = " + params[i] + "("+ params[i].getClass().getName() +")"); } try { returnedObject = m.invoke(object, params); // System.out.println("returnedObject = " + returnedObject); } catch (Exception e) { e.printStackTrace(); return returnJsonRpcError(call.get("id"), e); } } break; } } ObjectNode jsret = JsonNodeFactory.instance.objectNode(); jsret.put("jsonrpc", "2.0"); jsret.put("id", call.get("id").toString()); if (returnedObject != null) { addResult(jsret, returnedObject); } // System.out.println("jsret.toString() = " + jsret.toString()); return jsret.toString().getBytes(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.stratio.ingestion.sink.mongodb.MongoSinkTest.java
@Test public void basicTest() throws Exception { Transaction tx = channel.getTransaction(); tx.begin();/*from w ww . j ava 2s.co m*/ ObjectNode jsonBody = new ObjectNode(JsonNodeFactory.instance); jsonBody.put("myString", "foo"); jsonBody.put("myInt32", 32); Map<String, String> headers = new HashMap<String, String>(); headers.put("myString", "bar"); // Overwrites the value defined in JSON body headers.put("myInt64", "64"); headers.put("myBoolean", "true"); headers.put("myDouble", "1.0"); headers.put("myNull", null); Date myDate = new Date(); headers.put("myDate", Long.toString(myDate.getTime())); headers.put("myString2", "baz"); Event event = EventBuilder.withBody(jsonBody.toString().getBytes(Charsets.UTF_8), headers); channel.put(event); tx.commit(); tx.close(); mongoSink.process(); DBObject result = fongo.getDB("test").getCollection("test").findOne(); // System.out.println(result.toString()); assertThat(result).isNotNull(); assertThat(result.get("myString")).isEqualTo("bar"); assertThat(result.get("myInt32")).isEqualTo(32); assertThat(result.get("myInt32")).isInstanceOf(Integer.class); assertThat(result.get("myInt64")).isEqualTo(64L); assertThat(result.get("myInt64")).isInstanceOf(Long.class); assertThat(result.get("myBoolean")).isEqualTo(true); assertThat(result.get("myDouble")).isEqualTo(1.0); assertThat(result.get("myNull")).isNull(); assertThat(result.get("myDate")).isEqualTo(myDate); assertThat(result.get("myString2")).isNull(); assertThat(result.get("myStringMapped")).isEqualTo("baz"); }
From source file:org.jetbrains.webdemo.help.HelpLoader.java
private void generateHelpForWords() { resultWords = new ArrayNode(JsonNodeFactory.instance); try {/* w w w . j a va2s . c o m*/ File file = new File( CommonSettings.HELP_DIRECTORY + File.separator + ApplicationSettings.HELP_FOR_WORDS); Document doc = ResponseUtils.getXmlDocument(file); if (doc == null) { return; } NodeList nodeList = doc.getElementsByTagName("keyword"); for (int temp = 0; temp < nodeList.getLength(); temp++) { Node node = nodeList.item(temp); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; ObjectNode jsonObject = resultWords.addObject(); jsonObject.put("word", getTagValue("name", element)); jsonObject.put("help", getTagValueWithInnerTags("text", element)); } } } catch (Exception e) { ErrorWriter.ERROR_WRITER.writeExceptionToExceptionAnalyzer(e, SessionInfo.TypeOfRequest.LOAD_EXAMPLE.name(), "unknown", ""); } response.append("\nHelp for keywords was loaded."); }
From source file:com.muk.services.api.impl.PayPalPaymentService.java
@Override public Map<String, Object> commitPayment(String paymentId, String payerId) { final Map<String, Object> response = new HashMap<String, Object>(); final ObjectNode payload = JsonNodeFactory.instance.objectNode(); payload.put("payer_id", payerId); final ResponseEntity<JsonNode> paymentResponse = send("/payments/payment/" + paymentId + "/execute", payload);/*from www . j a v a 2 s. co m*/ if (!"approved".equals(paymentResponse.getBody().get("state").asText())) { response.put("error", "Unexpected status: " + paymentResponse.getBody().get("state").asText()); } else { response.put("success", true); } return response; }
From source file:net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtilsTest.java
/** * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtils#getPortName(int, java.util.Map)}. *//*ww w .ja v a 2s .com*/ @Test public void testGetPortNameIntMapOfStringString() { assertEquals("A", SpreadsheetUtils.getPortName(0, null)); assertEquals("AA", SpreadsheetUtils.getPortName(26, null)); ObjectNode configuration = JsonNodeFactory.instance.objectNode(); ArrayNode columnNames = configuration.arrayNode(); columnNames.addObject().put("column", "D").put("port", "delta"); configuration.put("columnNames", columnNames); assertEquals("delta", SpreadsheetUtils.getPortName(3, configuration)); assertEquals("AB", SpreadsheetUtils.getPortName(27, configuration)); }
From source file:io.gs2.auth.Gs2AuthClient.java
/** * 1???????<br>/* w w w . ja va 2s.c o m*/ * ?????????????????????1???????????<br> * <br> * * @param request * @return ? */ public CreateTimeOnetimeTokenResult createTimeOnetimeToken(CreateTimeOnetimeTokenRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode().put("scriptName", request.getScriptName()); HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/onetime/time/token", credential, ENDPOINT, CreateTimeOnetimeTokenRequest.Constant.MODULE, CreateTimeOnetimeTokenRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { post.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } return doRequest(post, CreateTimeOnetimeTokenResult.class); }
From source file:com.github.fge.jsonschema.servlets.SyntaxValidateServlet.java
@VisibleForTesting static JsonNode buildResult(final String rawSchema) throws IOException, ProcessingException { final ObjectNode ret = JsonNodeFactory.instance.objectNode(); final boolean invalidSchema = fillWithData(ret, Response.SCHEMA, Response.INVALID_SCHEMA, rawSchema); final JsonNode schemaNode = ret.remove(Response.SCHEMA); if (invalidSchema) return ret; final SchemaTree tree = new CanonicalSchemaTree(schemaNode); final SchemaHolder holder = new SchemaHolder(tree); final ListProcessingReport report = new ListProcessingReport(); PROCESSOR.process(report, holder);//from www. j av a 2 s. c om final boolean success = report.isSuccess(); ret.put(Response.VALID, success); ret.put(Response.RESULTS, report.asJson()); return ret; }