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.muk.services.facades.impl.DefaultPaymentFacade.java
@Override public Map<String, Object> startPayment(PaymentRequest paymentRequest, UriComponents redirectComponents) { Map<String, Object> response = new HashMap<String, Object>(); final ObjectNode payload = JsonNodeFactory.instance.objectNode(); if (ServiceConstants.PaymentMethods.paypalExpress.equals(paymentRequest.getPaymentMethod())) { payload.put("intent", "sale"); final ObjectNode redirectUrls = payload.putObject("redirect_urls"); redirectUrls.put("return_url", redirectComponents.toUriString() + "/id/redirect"); redirectUrls.put("cancel_url", redirectComponents.toUriString() + "/id/cancel"); final ObjectNode payer = payload.putObject("payer"); payer.put("payment_method", "paypal"); final ArrayNode transactions = payload.putArray("transactions"); final ObjectNode transaction = transactions.addObject(); transaction.put("description", paymentRequest.getService()); transaction.putObject("amount").put("total", paymentRequest.getPrice()).put("currency", "USD"); response = paypalPaymentService.startPayment(payload); } else if (ServiceConstants.PaymentMethods.stripe.equals(paymentRequest.getPaymentMethod())) { payload.put("amount", (long) Math.floor(paymentRequest.getPrice() * 100d)); payload.put("currency", "usd"); payload.put("description", paymentRequest.getService()); payload.put("source", paymentRequest.getInfo()); if (StringUtils.isNotBlank(paymentRequest.getEmail())) { payload.put("receipt_email", paymentRequest.getEmail()); }//from w ww . j a v a 2s .co m if (paymentRequest.getMetadata() != null) { final ObjectNode mds = payload.putObject("metadata"); for (final Pair<String, String> pair : paymentRequest.getMetadata()) { mds.put(pair.getLeft(), pair.getRight()); } } response = stripePaymentService.startPayment(payload); } return response; }
From source file:juzu.plugin.jackson.AbstractJacksonResponseTestCase.java
@Test public void testResponse() throws Exception { HttpGet get = new HttpGet(applicationURL().toString()); HttpClient client = HttpClientBuilder.create().build(); HttpResponse response = client.execute(get); assertEquals(200, response.getStatusLine().getStatusCode()); assertNotNull(response.getEntity()); assertEquals("application/json;charset=ISO-8859-1", response.getEntity().getContentType().getValue()); ObjectMapper mapper = new ObjectMapper(); JsonNode tree = mapper.readTree(response.getEntity().getContent()); JsonNodeFactory factory = JsonNodeFactory.instance; JsonNode expected = factory.objectNode().set("foo", factory.textNode("bar")); assertEquals(expected, tree);/*w w w .j av a 2 s .co m*/ }
From source file:org.springframework.cloud.aws.messaging.support.converter.NotificationRequestConverterTest.java
@Test public void fromMessage_withMessageAndSubject_shouldReturnMessage() throws Exception { // Arrange//from w w w.j a va2 s . c om ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); jsonObject.put("Type", "Notification"); jsonObject.put("Subject", "Hello"); jsonObject.put("Message", "World"); String payload = jsonObject.toString(); // Act Object notificationRequest = new NotificationRequestConverter() .fromMessage(MessageBuilder.withPayload(payload).build(), null); // Assert assertTrue(NotificationRequestConverter.NotificationRequest.class.isInstance(notificationRequest)); assertEquals("Hello", ((NotificationRequestConverter.NotificationRequest) notificationRequest).getSubject()); assertEquals("World", ((NotificationRequestConverter.NotificationRequest) notificationRequest).getMessage()); }
From source file:com.turn.shapeshifter.AutoSerializer.java
/** * {@inheritDoc}/*from w w w . ja v a 2s. c o m*/ * @throws SerializationException */ @Override public JsonNode serialize(Message message, ReadableSchemaRegistry registry) throws SerializationException { ObjectNode object = new ObjectNode(JsonNodeFactory.instance); for (Descriptors.FieldDescriptor field : descriptor.getFields()) { String propertyName = AutoSchema.PROTO_FIELD_CASE_FORMAT.to(AutoSchema.JSON_FIELD_CASE_FORMAT, field.getName()); if (field.isRepeated()) { if (message.getRepeatedFieldCount(field) > 0) { ArrayNode array = serializeRepeatedField(message, field, registry); if (array.size() != 0) { object.put(propertyName, array); } } } else if (message.hasField(field)) { Object value = message.getField(field); JsonNode fieldNode = serializeValue(value, field, registry); if (!fieldNode.isNull()) { object.put(propertyName, fieldNode); } } } if (object.size() == 0) { return NullNode.instance; } return object; }
From source file:com.github.fge.jsonpatch.mergepatch.NonObjectMergePatchTest.java
@Test public void patchYellsOnNullInput() throws JsonPatchException { try {//w w w .j a v a 2 s . c o m JsonMergePatch.fromJson(JsonNodeFactory.instance.arrayNode()).apply(null); fail("No exception thrown!"); } catch (NullPointerException e) { assertEquals(e.getMessage(), BUNDLE.getMessage("jsonPatch.nullValue")); } }
From source file:io.liveoak.testtools.AbstractResourceTestCase.java
protected void loadExtension(String id, Extension ext, ObjectNode extConfig, ObjectNode instancesConfig) throws Exception { ObjectNode fullConfig = JsonNodeFactory.instance.objectNode(); fullConfig.put("config", extConfig); if (instancesConfig != null) { fullConfig.put("instances", instancesConfig); }//from w w w .j a v a 2s.com this.system.extensionInstaller().load(id, ext, fullConfig); this.extensionIds.add(id); this.system.awaitStability(); }
From source file:com.github.fge.jsonschema.process.Index.java
private static JsonNode buildResult(final String rawSchema, final String rawData) throws IOException { final ObjectNode ret = JsonNodeFactory.instance.objectNode(); final boolean invalidSchema = fillWithData(ret, INPUT, INVALID_INPUT, rawSchema); final boolean invalidData = fillWithData(ret, INPUT2, INVALID_INPUT2, rawData); final JsonNode schemaNode = ret.remove(INPUT); final JsonNode data = ret.remove(INPUT2); if (invalidSchema || invalidData) return ret; final ProcessingReport report = VALIDATOR.validateUnchecked(schemaNode, data); final boolean success = report.isSuccess(); ret.put(VALID, success);/*ww w. j av a 2s . co m*/ final JsonNode node = ((AsJson) report).asJson(); ret.put(RESULTS, JacksonUtils.prettyPrint(node)); return ret; }
From source file:org.jsonschema2pojo.rules.PropertiesRule.java
/** * Applies this schema rule to take the required code generation steps. * <p>//from www .j a v a2 s . com * For each property present within the properties node, this rule will * invoke the 'property' rule provided by the given schema mapper. * * @param nodeName * the name of the node for which properties are being added * @param node * the properties node, containing property names and their * definition * @param jclass * the Java type which will have the given properties added * @return the given jclass */ @Override public JDefinedClass apply(String nodeName, JsonNode node, JDefinedClass jclass, Schema schema) { if (node == null) { node = JsonNodeFactory.instance.objectNode(); } for (Iterator<String> properties = node.fieldNames(); properties.hasNext();) { String property = properties.next(); ruleFactory.getPropertyRule().apply(property, node.get(property), jclass, schema); } if (ruleFactory.getGenerationConfig().isGenerateBuilders()) { if (!jclass._extends().name().equals("Object")) { addOverrideBuilders(jclass, jclass.owner()._getClass(jclass._extends().fullName())); } } ruleFactory.getAnnotator().propertyOrder(jclass, node); return jclass; }
From source file:de.thingweb.servient.HrefBindingTest.java
@Test public void testMultipleHrefs() throws Exception { // create GoPiGo thing Thing goPiGo = new Thing("GoPiGoTest"); assertTrue(goPiGo != null);//from w w w .ja v a 2 s.c o m ObjectNode valueTypeSpeed = JsonNodeFactory.instance.objectNode().put("type", "integer").put("minimum", 0) .put("maximum", 255); Property pSpeedLeft = new Property.Builder("speedLeft").setValueType(valueTypeSpeed) .setHrefs(Arrays.asList(new String[] { "speedLeft", "sl" })).setWriteable(true).build(); assertTrue(pSpeedLeft != null); goPiGo.addProperty(pSpeedLeft); final TokenRequirements tokenRequirements = null; ThingServer server = ServientBuilder.newThingServer(tokenRequirements); ThingInterface ti = server.addThing(goPiGo); assertTrue(ti != null); }
From source file:net.sf.taverna.t2.activities.beanshell.BeanshellActivityHealthCheckerTest.java
@Before public void setup() throws Exception { configuration = JsonNodeFactory.instance.objectNode(); configuration.put("classLoaderSharing", "workflow"); }