List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:org.ms123.common.workflow.converter.Simpl4CamelTaskJsonConverter.java
protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) { ServiceTask task = new ServiceTask(); Map elementMap = (Map) m_ds.deserialize(elementNode.toString()); Map<String, Object> propMap = (Map) elementMap.get("properties"); String clazz = Simpl4BpmnJsonConverter.getFullnameForTask("TaskCamelExecutor"); task.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS); task.setImplementation(clazz);// w ww .ja v a2 s .c o m FieldExtension field = new FieldExtension(); field.setFieldName(VARMAPPING); String variablesmapping = getValue(VARMAPPING, propMap.get(VARMAPPING_PROP)); field.setExpression(variablesmapping); task.getFieldExtensions().add(field); field = new FieldExtension(); field.setFieldName(NAMESPACE); field.setStringValue(getValue(NAMESPACE, propMap.get(NAMESPACE_PROP))); task.getFieldExtensions().add(field); field = new FieldExtension(); field.setFieldName(ROUTENAME); field.setStringValue(getValue(ROUTENAME, propMap.get(ROUTENAME_PROP))); task.getFieldExtensions().add(field); field = new FieldExtension(); field.setFieldName(ROUTEVARNAME); field.setStringValue(getValue(ROUTEVARNAME, propMap.get(ROUTEVARNAME_PROP))); task.getFieldExtensions().add(field); field = new FieldExtension(); field.setFieldName(RETURNVARIABLE); field.setStringValue(checkNull(RETURNVARIABLE, propMap.get(RETURNVARIABLE_PROP))); task.getFieldExtensions().add(field); return task; }
From source file:com.github.fge.jsonschema2avro.AvroWriterProcessorTest.java
@Test(dataProvider = "testData") public final void JsonSchemasAreCorrectlyTranslated(final JsonNode schema, final JsonNode avro) throws ProcessingException { final SchemaTree tree = new CanonicalSchemaTree(schema); final ValueHolder<SchemaTree> input = ValueHolder.hold("schema", tree); final Schema expected = new Schema.Parser().parse(avro.toString()); final Schema actual = processor.process(report, input).getValue(); assertEquals(expected, actual);/*from w w w . java 2 s . c o m*/ }
From source file:com.kelveden.rastajax.servlet.DefaultJsonServlet.java
private void writeRepresentationToResponse(JsonNode representation, HttpServletResponse httpResponse) throws IOException { httpResponse.setContentType("application/json; charset=utf8"); final OutputStream outputStream = httpResponse.getOutputStream(); outputStream.write(representation.toString().getBytes("UTF-8")); outputStream.flush();//w ww . j a v a2 s .c om }
From source file:com.github.fge.jsonschema.load.URIManagerTest.java
@Test public void URIRedirectionIsFollowed() throws IOException, ProcessingException { /*/*from ww w. j a va 2 s. c o m*/ * The content we return */ final JsonNode expected = JacksonUtils.nodeFactory().objectNode().put("hello", "world"); final InputStream sampleStream = new ByteArrayInputStream(expected.toString().getBytes()); /* * We need to build both the source URI and destination URI. As they are * both transformed to valid JSON References internally, we also build * JsonRef-compatible URIs (ie, with a fragment, even empty). * * The user, however, may supply URIs which are not JsonRef-compatible. */ final String source = "http://some.site/schema.json"; final String destination = "foo://real/location.json"; final URI sourceURI = JsonRef.fromString(source).getLocator(); final URI destinationURI = JsonRef.fromString(destination).getLocator(); /* * Build another mock for the original source URI protocol, make it * return the same thing as the target URI. Register both downloaders. */ when(mock.fetch(destinationURI)).thenReturn(sampleStream); final URIDownloader httpMock = mock(URIDownloader.class); when(httpMock.fetch(sourceURI)).thenReturn(sampleStream); final LoadingConfiguration cfg = LoadingConfiguration.newBuilder().addScheme("http", httpMock) .addScheme("foo", mock).addSchemaRedirect(source, destination).freeze(); final URIManager manager = new URIManager(cfg); /* * Get the original source... */ final JsonNode actual = manager.getContent(sourceURI); /* * And verify that it has been downloaded from the target, not the * source */ verify(httpMock, never()).fetch(any(URI.class)); verify(mock).fetch(destinationURI); /* * Finally, ensure the correctness of the downloaded content. */ assertEquals(actual, expected); }
From source file:com.redhat.lightblue.eval.ArrayQueryProjectorTest.java
@Test public void array_query_projection_with_no_match() throws Exception { Projection p = EvalTestContext.projectionFromJson( "{'field':'field7','match':{'field':'elemf3','op':'>','rvalue':25},'project':{'field':'*'}}"); Projector projector = Projector.getInstance(p, md); JsonNode expectedNode = JsonUtils.json("{}".replace('\'', '\"')); JsonDoc pdoc = projector.project(jsonDoc, JSON_NODE_FACTORY); Assert.assertEquals(expectedNode.toString(), pdoc.toString()); }
From source file:com.redhat.lightblue.eval.ArrayQueryProjectorTest.java
@Test public void one_$parent_array_query_projection_with_no_match() throws Exception { Projection p = EvalTestContext.projectionFromJson( "{'field':'field6.$parent.field7','match':{'field':'elemf3','op':'>','rvalue':25},'project':{'field':'*'}}"); Projector projector = Projector.getInstance(p, md); JsonNode expectedNode = JsonUtils.json("{}".replace('\'', '\"')); JsonDoc pdoc = projector.project(jsonDoc, JSON_NODE_FACTORY); Assert.assertEquals(expectedNode.toString(), pdoc.toString()); }
From source file:com.redhat.lightblue.eval.ArrayQueryProjectorTest.java
@Test public void two_$parent_array_query_projection_with_no_match() throws Exception { Projection p = EvalTestContext.projectionFromJson( "{'field':'field6.nf7.$parent.$parent.field7','match':{'field':'elemf3','op':'>','rvalue':25},'project':{'field':'*'}}"); Projector projector = Projector.getInstance(p, md); JsonNode expectedNode = JsonUtils.json("{}".replace('\'', '\"')); JsonDoc pdoc = projector.project(jsonDoc, JSON_NODE_FACTORY); Assert.assertEquals(expectedNode.toString(), pdoc.toString()); }
From source file:com.redhat.lightblue.eval.ArrayQueryProjectorTest.java
@Test public void one_$this_array_query_projection_with_no_match() throws Exception { Projection p = EvalTestContext.projectionFromJson( "{'field':'field7.$this','match':{'field':'elemf3','op':'>','rvalue':25},'project':{'field':'*'}}"); Projector projector = Projector.getInstance(p, md); JsonNode expectedNode = JsonUtils.json("{}".replace('\'', '\"')); JsonDoc pdoc = projector.project(jsonDoc, JSON_NODE_FACTORY); Assert.assertEquals(expectedNode.toString(), pdoc.toString()); }
From source file:io.orchestrate.client.EventFetchOperation.java
/** {@inheritDoc} */ @Override// w w w . j a v a 2 s.co m @SuppressWarnings("unchecked") Iterable<Event<T>> fromResponse(final int status, final HttpHeader httpHeader, final String json, final JacksonMapper mapper) throws IOException { assert (status == 200); final ObjectMapper objectMapper = mapper.getMapper(); final JsonNode jsonNode = objectMapper.readTree(json); final int count = jsonNode.get("count").asInt(); final List<Event<T>> events = new ArrayList<Event<T>>(count); final Iterator<JsonNode> iter = jsonNode.get("results").elements(); while (iter.hasNext()) { final JsonNode result = iter.next(); final long timestamp = result.get("timestamp").asLong(); final JsonNode valueNode = result.get("value"); final String rawValue = valueNode.toString(); final T value; if (clazz == String.class) { // don't deserialize JSON data value = (T) rawValue; } else { value = objectMapper.readValue(rawValue, clazz); } events.add(new Event<T>(value, rawValue, timestamp)); } return events; }
From source file:io.wcm.caravan.pipeline.impl.JacksonFunctionsTest.java
@Test public void testPojoToNode() { JsonNode result = JacksonFunctions.pojoToNode(createSimplePojo(123, "abc")); // match generated JSON from POJO with expected JSON as String assertEquals("{\"id\":123,\"name\":\"abc\"}", result.toString()); }