Example usage for com.fasterxml.jackson.core JsonGenerator writeStartObject

List of usage examples for com.fasterxml.jackson.core JsonGenerator writeStartObject

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonGenerator writeStartObject.

Prototype

public abstract void writeStartObject() throws IOException, JsonGenerationException;

Source Link

Document

Method for writing starting marker of a JSON Object value (character '{'; plus possible white space decoration if pretty-printing is enabled).

Usage

From source file:net.echinopsii.ariane.community.plugin.rabbitmq.directory.json.RabbitmqNodeJSON.java

public final static void manyRabbitmqNodes2JSON(HashSet<RabbitmqNode> nodes, ByteArrayOutputStream outStream)
        throws IOException {
    JsonGenerator jgenerator = RabbitmqDirectoryBootstrap.getjFactory().createGenerator(outStream,
            JsonEncoding.UTF8);/*from  w  w  w  .  j a v  a  2  s  . c om*/
    jgenerator.writeStartObject();
    jgenerator.writeArrayFieldStart("rabbitmqnodes");
    for (RabbitmqNode node : nodes)
        rabbitmqNode2JSON(node, jgenerator);
    jgenerator.writeEndArray();
    jgenerator.writeEndObject();
    jgenerator.close();
}

From source file:com.cedarsoft.couchdb.io.ActionResponseSerializerTest.java

License:asdf

/**
 * Only used for tests/*from   www .  j a va2  s  .  c  o  m*/
 * @param object
 * @param out
 * @throws IOException
 */
@Deprecated
public static void serialize(@Nonnull ActionResponse object, @Nonnull OutputStream out) throws IOException {
    JsonFactory jsonFactory = JacksonSupport.getJsonFactory();

    JsonGenerator generator = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);

    generator.writeStartObject();

    serialize(generator, object);
    generator.writeEndObject();

    generator.close();
}

From source file:net.echinopsii.ariane.community.core.directory.wat.json.ds.technical.system.OSInstanceJSON.java

public final static void manyOSInstances2JSON(HashSet<OSInstance> osInstances, ByteArrayOutputStream outStream)
        throws IOException {
    JsonGenerator jgenerator = DirectoryBootstrap.getjFactory().createGenerator(outStream, JsonEncoding.UTF8);
    jgenerator.writeStartObject();
    jgenerator.writeArrayFieldStart("osInstances");
    Iterator<OSInstance> iter = osInstances.iterator();
    while (iter.hasNext()) {
        OSInstance current = iter.next();
        OSInstanceJSON.osInstance2JSON(current, jgenerator);
    }//from  ww w.  j av a 2  s . c  om
    jgenerator.writeEndArray();
    jgenerator.writeEndObject();
    jgenerator.close();
}

From source file:com.netflix.hystrix.contrib.sample.stream.HystrixUtilizationJsonStream.java

protected static String convertToJson(HystrixUtilization utilization) throws IOException {
    StringWriter jsonString = new StringWriter();
    JsonGenerator json = jsonFactory.createGenerator(jsonString);

    json.writeStartObject();
    json.writeStringField("type", "HystrixUtilization");
    json.writeObjectFieldStart("commands");
    for (Map.Entry<HystrixCommandKey, HystrixCommandUtilization> entry : utilization.getCommandUtilizationMap()
            .entrySet()) {/*w  w w .  ja  va  2s  . co  m*/
        final HystrixCommandKey key = entry.getKey();
        final HystrixCommandUtilization commandUtilization = entry.getValue();
        writeCommandUtilizationJson(json, key, commandUtilization);

    }
    json.writeEndObject();

    json.writeObjectFieldStart("threadpools");
    for (Map.Entry<HystrixThreadPoolKey, HystrixThreadPoolUtilization> entry : utilization
            .getThreadPoolUtilizationMap().entrySet()) {
        final HystrixThreadPoolKey threadPoolKey = entry.getKey();
        final HystrixThreadPoolUtilization threadPoolUtilization = entry.getValue();
        writeThreadPoolUtilizationJson(json, threadPoolKey, threadPoolUtilization);
    }
    json.writeEndObject();
    json.writeEndObject();
    json.close();

    return jsonString.getBuffer().toString();
}

From source file:io.seldon.spark.actions.JobUtils.java

public static String mapToJson(Map<String, String> m) {
    JsonFactory jsonFactory = new JsonFactory();
    StringWriter sw = new StringWriter();
    try {/*from   w  ww .  j a v  a  2s  .c  o m*/
        JsonGenerator jg = jsonFactory.createGenerator(sw);
        jg.writeStartObject();
        for (Map.Entry<String, String> entry : m.entrySet()) {
            jg.writeStringField(entry.getKey(), entry.getValue());
        }
        jg.writeEndObject();
        jg.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return sw.toString();
}

From source file:io.seldon.spark.actions.JobUtils.java

public static String getJsonFromActionData(ActionData actionData) {
    JsonFactory jsonFactory = new JsonFactory();
    StringWriter sw = new StringWriter();
    try {/* w  w w  . ja  v a  2  s .co m*/
        JsonGenerator jg = jsonFactory.createGenerator(sw);
        jg.writeStartObject();
        jg.writeStringField("timestamp_utc", actionData.timestamp_utc);
        jg.writeStringField("client", actionData.client);
        jg.writeStringField("client_userid", actionData.client_userid);
        jg.writeNumberField("userid", actionData.userid);
        jg.writeNumberField("itemid", actionData.itemid);
        jg.writeStringField("client_itemid", actionData.client_itemid);
        jg.writeStringField("rectag", actionData.rectag);
        jg.writeNumberField("type", actionData.type);
        jg.writeNumberField("value", actionData.value);
        jg.writeEndObject();
        jg.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return sw.toString();
}

From source file:com.netflix.hystrix.serial.SerialHystrixConfiguration.java

private static void serializeConfiguration(HystrixConfiguration config, JsonGenerator json) {
    try {//from   w  w  w.  j a v a2s  . c o m
        json.writeStartObject();
        json.writeStringField("type", "HystrixConfig");
        json.writeObjectFieldStart("commands");
        for (Map.Entry<HystrixCommandKey, HystrixCommandConfiguration> entry : config.getCommandConfig()
                .entrySet()) {
            final HystrixCommandKey key = entry.getKey();
            final HystrixCommandConfiguration commandConfig = entry.getValue();
            writeCommandConfigJson(json, key, commandConfig);

        }
        json.writeEndObject();

        json.writeObjectFieldStart("threadpools");
        for (Map.Entry<HystrixThreadPoolKey, HystrixThreadPoolConfiguration> entry : config
                .getThreadPoolConfig().entrySet()) {
            final HystrixThreadPoolKey threadPoolKey = entry.getKey();
            final HystrixThreadPoolConfiguration threadPoolConfig = entry.getValue();
            writeThreadPoolConfigJson(json, threadPoolKey, threadPoolConfig);
        }
        json.writeEndObject();

        json.writeObjectFieldStart("collapsers");
        for (Map.Entry<HystrixCollapserKey, HystrixCollapserConfiguration> entry : config.getCollapserConfig()
                .entrySet()) {
            final HystrixCollapserKey collapserKey = entry.getKey();
            final HystrixCollapserConfiguration collapserConfig = entry.getValue();
            writeCollapserConfigJson(json, collapserKey, collapserConfig);
        }
        json.writeEndObject();
        json.writeEndObject();
        json.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

From source file:com.netflix.hystrix.serial.SerialHystrixRequestEvents.java

private static void convertExecutionToJson(JsonGenerator json,
        HystrixRequestEvents.ExecutionSignature executionSignature, List<Integer> latencies)
        throws IOException {
    json.writeStartObject();
    json.writeStringField("name", executionSignature.getCommandName());
    json.writeArrayFieldStart("events");
    ExecutionResult.EventCounts eventCounts = executionSignature.getEventCounts();
    for (HystrixEventType eventType : HystrixEventType.values()) {
        if (!eventType.equals(HystrixEventType.COLLAPSED)) {
            if (eventCounts.contains(eventType)) {
                int eventCount = eventCounts.getCount(eventType);
                if (eventCount > 1) {
                    json.writeStartObject();
                    json.writeStringField("name", eventType.name());
                    json.writeNumberField("count", eventCount);
                    json.writeEndObject();
                } else {
                    json.writeString(eventType.name());
                }//  w w  w.j av  a2 s . c  o  m
            }
        }
    }
    json.writeEndArray();
    json.writeArrayFieldStart("latencies");
    for (int latency : latencies) {
        json.writeNumber(latency);
    }
    json.writeEndArray();
    if (executionSignature.getCachedCount() > 0) {
        json.writeNumberField("cached", executionSignature.getCachedCount());
    }
    if (executionSignature.getEventCounts().contains(HystrixEventType.COLLAPSED)) {
        json.writeObjectFieldStart("collapsed");
        json.writeStringField("name", executionSignature.getCollapserKey().name());
        json.writeNumberField("count", executionSignature.getCollapserBatchSize());
        json.writeEndObject();
    }
    json.writeEndObject();
}

From source file:com.cedarsoft.couchdb.DesignDocumentsUpdater.java

/**
 * Creates the json content for the design document
 *
 * @return a string containing the json content for this design document
 *
 * @throws IOException/*from  www  .j  a  va  2s . co  m*/
 */
public static String createJson(@Nonnull DesignDocument designDocument, @Nullable Revision revision)
        throws IOException {
    //noinspection TypeMayBeWeakened
    StringWriter writer = new StringWriter();
    JsonGenerator generator = new JsonFactory().createJsonGenerator(writer);
    generator.writeStartObject();

    generator.writeStringField("_id", designDocument.getId());
    if (revision != null) {
        generator.writeStringField("_rev", revision.asString());
    }
    generator.writeStringField("language", "javascript");

    generator.writeObjectFieldStart("views");

    for (View view : designDocument.getViews()) {
        generator.writeObjectFieldStart(view.getName());

        generator.writeStringField("map", view.getMappingFunction());
        @Nullable
        String reduceFunction = view.getReduceFunction();
        if (reduceFunction != null) {
            generator.writeStringField("reduce", reduceFunction);
        }
        generator.writeEndObject();
    }

    generator.writeEndObject();
    generator.writeEndObject();
    generator.flush();
    return writer.toString();
}

From source file:com.netflix.hystrix.contrib.requests.stream.HystrixRequestEventsJsonStream.java

private static void convertExecutionToJson(JsonGenerator json,
        HystrixRequestEvents.ExecutionSignature executionSignature, List<Integer> latencies)
        throws IOException {
    json.writeStartObject();
    json.writeStringField("name", executionSignature.getCommandName());
    json.writeArrayFieldStart("events");
    ExecutionResult.EventCounts eventCounts = executionSignature.getEventCounts();
    for (HystrixEventType eventType : HystrixEventType.values()) {
        if (eventType != HystrixEventType.COLLAPSED) {
            if (eventCounts.contains(eventType)) {
                int eventCount = eventCounts.getCount(eventType);
                if (eventCount > 1) {
                    json.writeStartObject();
                    json.writeStringField("name", eventType.name());
                    json.writeNumberField("count", eventCount);
                    json.writeEndObject();
                } else {
                    json.writeString(eventType.name());
                }/*from  w w w. j a  v a  2 s. co  m*/
            }
        }
    }
    json.writeEndArray();
    json.writeArrayFieldStart("latencies");
    for (int latency : latencies) {
        json.writeNumber(latency);
    }
    json.writeEndArray();
    if (executionSignature.getCachedCount() > 0) {
        json.writeNumberField("cached", executionSignature.getCachedCount());
    }
    if (executionSignature.getEventCounts().contains(HystrixEventType.COLLAPSED)) {
        json.writeObjectFieldStart("collapsed");
        json.writeStringField("name", executionSignature.getCollapserKey().name());
        json.writeNumberField("count", executionSignature.getCollapserBatchSize());
        json.writeEndObject();
    }
    json.writeEndObject();
}