Example usage for com.fasterxml.jackson.databind.node JsonNodeFactory instance

List of usage examples for com.fasterxml.jackson.databind.node JsonNodeFactory instance

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node JsonNodeFactory instance.

Prototype

JsonNodeFactory instance

To view the source code for com.fasterxml.jackson.databind.node JsonNodeFactory instance.

Click Source Link

Usage

From source file:io.liveoak.pgsql.BasePgSqlHttpTest.java

@BeforeClass
public static void loadExtensions() throws Exception {

    schema = "xlo_test_" + UUID.randomUUID().toString().substring(0, 8);
    schema_two = "xlo_test_" + UUID.randomUUID().toString().substring(0, 8);
    if (schema.compareTo(schema_two) > 0) {
        String tmp = schema;// w  w w. j a v a  2  s .  com
        schema = schema_two;
        schema_two = tmp;
    }
    loadExtension("pgsql", new PgSqlExtension(), JsonNodeFactory.instance.objectNode());
    try {
        installTestAppResource("pgsql", BASEPATH, createConfig());
    } catch (Exception e) {
        // Happens when datasource can not be configured
        e.printStackTrace();
    }
}

From source file:org.wrml.runtime.format.application.schema.json.JsonSchemaLoader.java

public JsonSchema load(final Schema wrmlSchema) {

    if (wrmlSchema == null) {
        return null;
    }//from   w  w  w  .  j  ava  2 s.  c  om

    final URI schemaUri = wrmlSchema.getUri();
    if (_JsonSchemas.containsKey(schemaUri)) {
        return _JsonSchemas.get(schemaUri);
    }

    final String schemaTitle = wrmlSchema.getTitle();
    final String schemaDescription = wrmlSchema.getDescription();

    final ObjectNode schemaNode = JsonNodeFactory.instance.objectNode();

    PropertyType.Id.setValue(schemaNode, schemaUri, getSyntaxLoader());
    PropertyType.Title.setValue(schemaNode, schemaTitle, getSyntaxLoader());
    PropertyType.Description.setValue(schemaNode, schemaDescription, getSyntaxLoader());
    PropertyType.Type.setValue(schemaNode, JsonType.Object.getKeyword(), getSyntaxLoader());

    initStringArrayNode(schemaNode, PropertyType.Extends.getName(), wrmlSchema.getBaseSchemaUris());

    initStringArrayNode(schemaNode, Schema.SLOT_NAME_KEY_SLOT_NAMES, wrmlSchema.getKeySlotNames());

    // TODO
    // wrmlSchema.getVersion();

    final ObjectNode propertiesNode = schemaNode.putObject(PropertyType.Properties.getName());
    final List<Slot> slots = wrmlSchema.getSlots();
    for (final Slot slot : slots) {

        final Value value = slot.getValue();
        if (value instanceof LinkValue) {
            initLinkSlotNode(schemaNode, slot);
        } else {
            final String slotName = slot.getName();
            final ObjectNode slotNode = propertiesNode.putObject(slotName);

            initPropertySlotNode(slotNode, slot);
        }

    }

    return load(schemaNode, schemaUri);
}

From source file:com.datamountaineer.streamreactor.connect.json.SimpleJsonConverterTest.java

@Test
public void structToJson() {
    Schema schema = SchemaBuilder.struct().field("field1", Schema.BOOLEAN_SCHEMA)
            .field("field2", Schema.STRING_SCHEMA).field("field3", Schema.STRING_SCHEMA)
            .field("field4", Schema.BOOLEAN_SCHEMA).build();
    Struct input = new Struct(schema).put("field1", true).put("field2", "string2").put("field3", "string3")
            .put("field4", false);
    JsonNode converted = converter.fromConnectData(schema, input);

    assertEquals(JsonNodeFactory.instance.objectNode().put("field1", true).put("field2", "string2")
            .put("field3", "string3").put("field4", false), converted);
}

From source file:io.syndesis.maven.ExtractConnectorDescriptorsMojo.java

private void addComponentMeta(ObjectNode root, ClassLoader classLoader) {
    // is there any custom Camel components in this library?
    ObjectNode component = new ObjectNode(JsonNodeFactory.instance);

    ObjectNode componentMeta = getComponentMeta(classLoader);
    if (componentMeta != null) {
        component.set("meta", componentMeta);
    }/* ww w. j  a va 2  s .c  o m*/
    addOptionalSchemaAsString(classLoader, component, "schema", "camel-component-schema.json");

    if (component.size() > 0) {
        root.set("component", component);
    }
}

From source file:org.jetbrains.webdemo.ResponseUtils.java

public static ObjectNode getErrorWithStackTraceAsJsonNode(String error, String stackTrace) {
    ObjectNode result = new ObjectNode(JsonNodeFactory.instance);
    result.put("type", "err");
    result.put("exception", error);
    result.put("stackTrace", stackTrace);
    return result;
}

From source file:org.eel.kitchen.jsonschema.uri.URIManagerTest.java

@Test
public void URIRedirectionIsFollowed() throws IOException, JsonSchemaException {
    /*/*from   ww  w  .  ja  v  a 2 s  .c o m*/
     * The content we return
     */
    final JsonNode expected = JsonNodeFactory.instance.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 from = "http://some.site/schema.json";
    final String to = "foo://real/location.json";
    manager.addRedirection(from, to);

    final URI source = JsonRef.fromString(from).getLocator();
    final URI target = JsonRef.fromString(to).getLocator();

    /*
     * Build another mock for the original source URI protocol, make it
     * return the same thing as the target URI. Register both downloaders.
     */
    final URIDownloader httpMock = mock(URIDownloader.class);
    when(httpMock.fetch(source)).thenReturn(sampleStream);
    manager.registerScheme("http", httpMock);

    when(mock.fetch(target)).thenReturn(sampleStream);
    manager.registerScheme("foo", mock);

    /*
     * Get the original source...
     */
    final JsonNode actual = manager.getContent(source);

    /*
     * And verify that it has been downloaded from the target, not the
     * source
     */
    verify(httpMock, never()).fetch(any(URI.class));
    verify(mock).fetch(target);

    /*
     * Finally, ensure the correctness of the downloaded content.
     */
    assertEquals(actual, expected);
}

From source file:com.stratio.ingestion.sink.druid.DruidSinkIT.java

private Event getEvent(long offset) {
    ObjectNode jsonBody = new ObjectNode(JsonNodeFactory.instance);
    jsonBody.put("field1", "foo");
    jsonBody.put("field2", 32);
    jsonBody.put("timestamp", String.valueOf(new Date().getTime()));

    Map<String, String> headers = new HashMap<String, String>();
    headers.put("field3", "bar"); // Overwrites the value defined in JSON body
    headers.put("field4", "64");
    headers.put("field5", "true");
    headers.put("field6", "1.0");
    headers.put("field7", "11");
    final long l = new Date().getTime();
    headers.put("timestamp", String.valueOf(l + offset));

    headers.put("myString2", "baz");

    return EventBuilder.withBody(jsonBody.toString().getBytes(Charsets.UTF_8), headers);
}

From source file:com.linkedin.drelephant.tuning.ParamGenerator.java

/**
 * Converts a list of particles to json/*from  w ww .jav  a 2s  .  c o  m*/
 * @param particleList Particle List
 * @return JsonNode
 */
private JsonNode particleListToJson(List<Particle> particleList) {
    JsonNode jsonNode;

    if (particleList == null) {
        jsonNode = JsonNodeFactory.instance.objectNode();
        logger.info("Null particleList, returning empty json");
    } else {
        jsonNode = Json.toJson(particleList);
    }
    return jsonNode;
}

From source file:org.attribyte.api.pubsub.impl.server.APIServlet.java

private void doTopicPost(HttpServletRequest request, final String topic, HttpServletResponse response)
        throws IOException, ServletException {
    try {/* w  ww .jav a 2 s  .  c  om*/
        Topic endpointTopic = datastore.getTopic(topic, true);
        Request checkRequest = fromServletRequest(request, DEFAULT_MAX_BODY_BYTES);
        for (URLFilter filter : topicFilters) {
            URLFilter.Result res = filter.apply(topic, checkRequest);
            if (res.rejected) {
                if (res.rejectReason != null) {
                    response.sendError(res.rejectCode, res.rejectReason);
                } else {
                    response.sendError(res.rejectCode);
                }
                return;
            }
        }

        ObjectNode responseNode = JsonNodeFactory.instance.objectNode();
        responseNode.put("name", endpointTopic.getURL());
        responseNode.put("id", endpointTopic.getId());
        sendJSONResponse(response, responseNode);
    } catch (DatastoreException de) {
        logger.error("Problem creating topic", de);
        sendServletResponse(INTERNAL_ERROR_RESPONSE, response);
    }
}

From source file:de.thomaskrille.dropwizard.environment_configuration.EnvironmentConfigurationFactory.java

/**
 * Loads, parses, binds, and validates a configuration object from an empty document.
 *
 * @return a validated configuration object
 * @throws IOException/*w  ww.  j  a  va  2s  . c  o m*/
 *         if there is an error reading the file
 * @throws ConfigurationException
 *         if there is an error parsing or validating the file
 */
public T build() throws IOException, ConfigurationException {
    return build(JsonNodeFactory.instance.objectNode(), "default configuration");
}