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:eu.project.ttc.readers.TermSuiteJsonCasSerializer.java

private static void writeWordAnnotations(JsonGenerator jg, JCas jCas) throws IOException {
    jg.writeStartArray();/*from   w  w  w.  ja va2  s  .c  om*/
    FSIterator<Annotation> it = jCas.getAnnotationIndex(WordAnnotation.type).iterator();
    while (it.hasNext()) {
        WordAnnotation wa = (WordAnnotation) it.next();
        jg.writeStartObject();
        writeStringField(jg, F_CATEGORY, wa.getCategory());
        writeStringField(jg, F_LEMMA, wa.getLemma());
        writeStringField(jg, F_STEM, wa.getStem());
        writeStringField(jg, F_TAG, wa.getTag());
        writeStringField(jg, F_SUB_CATEGORY, wa.getSubCategory());
        writeStringField(jg, F_REGEX_LABEL, wa.getRegexLabel());
        writeStringField(jg, F_NUMBER, wa.getNumber());
        writeStringField(jg, F_GENDER, wa.getGender());
        writeStringField(jg, F_CASE, wa.getCase());
        writeStringField(jg, F_MOOD, wa.getMood());
        writeStringField(jg, F_TENSE, wa.getTense());
        writeStringField(jg, F_PERSON, wa.getPerson());
        writeStringField(jg, F_DEGREE, wa.getDegree());
        writeStringField(jg, F_FORMATION, wa.getFormation());
        writeStringField(jg, F_LABELS, wa.getLabels());
        writeOffsets(jg, wa);
        jg.writeEndObject();
    }
    jg.writeEndArray();
}

From source file:org.apache.orc.bench.convert.json.JsonWriter.java

static void printRow(JsonGenerator writer, VectorizedRowBatch batch, TypeDescription schema, int row)
        throws IOException {
    if (schema.getCategory() == TypeDescription.Category.STRUCT) {
        List<TypeDescription> fieldTypes = schema.getChildren();
        List<String> fieldNames = schema.getFieldNames();
        writer.writeStartObject();
        for (int c = 0; c < batch.cols.length; ++c) {
            writer.writeFieldName(fieldNames.get(c));
            printValue(writer, batch.cols[c], fieldTypes.get(c), row);
        }/*from w  ww  .j a v a  2  s .  c  o  m*/
        writer.writeEndObject();
    } else {
        printValue(writer, batch.cols[0], schema, row);
    }
}

From source file:org.apache.orc.bench.convert.json.JsonWriter.java

private static void printMap(JsonGenerator writer, MapColumnVector vector, TypeDescription schema, int row)
        throws IOException {
    writer.writeStartArray();/*from   www  .j av a  2 s .c  o  m*/
    TypeDescription keyType = schema.getChildren().get(0);
    TypeDescription valueType = schema.getChildren().get(1);
    int offset = (int) vector.offsets[row];
    for (int i = 0; i < vector.lengths[row]; ++i) {
        writer.writeStartObject();
        writer.writeFieldName("_key");
        printValue(writer, vector.keys, keyType, offset + i);
        writer.writeFieldName("_value");
        printValue(writer, vector.values, valueType, offset + i);
        writer.writeEndObject();
    }
    writer.writeEndArray();
}

From source file:com.microsoft.azure.storage.table.TableEntitySerializer.java

/**
 * Reserved for internal use. Writes an entity to the specified <code>JsonGenerator</code> as a JSON resource
 * //from  ww w  .  ja  va  2  s  .c  om
 * @param generator
 *            The <code>JsonGenerator</code> to write the entity to.
 * @param options
 *            The {@link TableRequestOptions} to use for serializing.
 * @param entity
 *            The instance implementing {@link TableEntity} to write to the output stream.
 * @param isTableEntry
 *            A flag indicating the entity is a reference to a table at the top level of the storage service when
 *            <code>true<code> and a reference to an entity within a table when <code>false</code>.
 * @param opContext
 *            An {@link OperationContext} object used to track the execution of the operation.
 * 
 * @throws StorageException
 *             if a Storage service error occurs.
 * @throws IOException
 *             if an error occurs while accessing the stream.
 */
private static void writeJsonEntity(final JsonGenerator generator, final TableRequestOptions options,
        final TableEntity entity, final boolean isTableEntry, final OperationContext opContext)
        throws StorageException, IOException {

    Map<String, EntityProperty> properties = getPropertiesFromDictionary(entity, options, opContext);

    // start object
    generator.writeStartObject();

    if (!isTableEntry) {
        Utility.assertNotNull(TableConstants.PARTITION_KEY, entity.getPartitionKey());
        Utility.assertNotNull(TableConstants.ROW_KEY, entity.getRowKey());
        Utility.assertNotNull(TableConstants.TIMESTAMP, entity.getTimestamp());

        // PartitionKey
        generator.writeStringField(TableConstants.PARTITION_KEY, entity.getPartitionKey());

        // RowKey
        generator.writeStringField(TableConstants.ROW_KEY, entity.getRowKey());

        // Timestamp
        generator.writeStringField(TableConstants.TIMESTAMP, Utility.getJavaISO8601Time(entity.getTimestamp()));
    }

    for (final Entry<String, EntityProperty> ent : properties.entrySet()) {
        if (ent.getKey().equals(TableConstants.PARTITION_KEY) || ent.getKey().equals(TableConstants.ROW_KEY)
                || ent.getKey().equals(TableConstants.TIMESTAMP) || ent.getKey().equals("Etag")) {
            continue;
        }

        EntityProperty currProp = ent.getValue();
        if (currProp.getEdmType().mustAnnotateType()) {
            final String edmTypeString = currProp.getEdmType().toString();

            // property type
            generator.writeStringField(ent.getKey() + ODataConstants.ODATA_TYPE_SUFFIX, edmTypeString);

            // property key and value
            generator.writeStringField(ent.getKey(), ent.getValue().getValueAsString());
        } else if (currProp.getEdmType() == EdmType.DOUBLE && currProp.getIsNull() == false) {
            final String edmTypeString = currProp.getEdmType().toString();
            final Double value = currProp.getValueAsDouble();

            // property type, if needed
            if (value.equals(Double.POSITIVE_INFINITY) || value.equals(Double.NEGATIVE_INFINITY)
                    || value.equals(Double.NaN)) {
                generator.writeStringField(ent.getKey() + ODataConstants.ODATA_TYPE_SUFFIX, edmTypeString);

                // property key and value
                generator.writeStringField(ent.getKey(), ent.getValue().getValueAsString());
            } else {
                writeJsonProperty(generator, ent);
            }

        } else {
            writeJsonProperty(generator, ent);
        }
    }

    // end object
    generator.writeEndObject();
}

From source file:io.protostuff.JsonIOUtil.java

/**
 * Serializes the {@code message} into a JsonGenerator using the given {@code schema}.
 *///www  .  j ava 2s .co m
public static <T> void writeTo(JsonGenerator generator, T message, Schema<T> schema, boolean numeric)
        throws IOException {
    generator.writeStartObject();

    final JsonOutput output = new JsonOutput(generator, numeric, schema);
    schema.writeTo(output, message);
    if (output.isLastRepeated())
        generator.writeEndArray();

    generator.writeEndObject();
}

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

private static void writeThreadPoolMetrics(final HystrixThreadPoolMetrics threadPoolMetrics, JsonGenerator json)
        throws IOException {
    HystrixThreadPoolKey key = threadPoolMetrics.getThreadPoolKey();

    json.writeStartObject();

    json.writeStringField("type", "HystrixThreadPool");
    json.writeStringField("name", key.name());
    json.writeNumberField("currentTime", System.currentTimeMillis());

    json.writeNumberField("currentActiveCount", threadPoolMetrics.getCurrentActiveCount().intValue());
    json.writeNumberField("currentCompletedTaskCount",
            threadPoolMetrics.getCurrentCompletedTaskCount().longValue());
    json.writeNumberField("currentCorePoolSize", threadPoolMetrics.getCurrentCorePoolSize().intValue());
    json.writeNumberField("currentLargestPoolSize", threadPoolMetrics.getCurrentLargestPoolSize().intValue());
    json.writeNumberField("currentMaximumPoolSize", threadPoolMetrics.getCurrentMaximumPoolSize().intValue());
    json.writeNumberField("currentPoolSize", threadPoolMetrics.getCurrentPoolSize().intValue());
    json.writeNumberField("currentQueueSize", threadPoolMetrics.getCurrentQueueSize().intValue());
    json.writeNumberField("currentTaskCount", threadPoolMetrics.getCurrentTaskCount().longValue());
    safelyWriteNumberField(json, "rollingCountThreadsExecuted", new Func0<Long>() {
        @Override/*from  www .j a va2 s. c  o  m*/
        public Long call() {
            return threadPoolMetrics.getRollingCount(HystrixEventType.ThreadPool.EXECUTED);
        }
    });
    json.writeNumberField("rollingMaxActiveThreads", threadPoolMetrics.getRollingMaxActiveThreads());
    safelyWriteNumberField(json, "rollingCountCommandRejections", new Func0<Long>() {
        @Override
        public Long call() {
            return threadPoolMetrics.getRollingCount(HystrixEventType.ThreadPool.REJECTED);
        }
    });

    json.writeNumberField("propertyValue_queueSizeRejectionThreshold",
            threadPoolMetrics.getProperties().queueSizeRejectionThreshold().get());
    json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds",
            threadPoolMetrics.getProperties().metricsRollingStatisticalWindowInMilliseconds().get());

    json.writeNumberField("reportingHosts", 1); // this will get summed across all instances in a cluster

    json.writeEndObject();
}

From source file:com.attribyte.essem.ESReporter.java

static final void generateCounter(final JsonGenerator generator, final ReportProtos.EssemReport.Counter counter,
        final String application, final String host, final String instance, final long timestamp)
        throws IOException {
    generator.writeStartObject();
    writeStringField(generator, Fields.APPLICATION_FIELD, application);
    writeStringField(generator, Fields.HOST_FIELD, host);
    writeStringField(generator, Fields.INSTANCE_FIELD, instance);
    writeStringField(generator, Fields.NAME_FIELD, counter.getName().trim());
    generator.writeNumberField(Fields.COUNT_FIELD, counter.getCount());
    generator.writeNumberField(Fields.TIMESTAMP_FIELD, timestamp);
    generator.writeEndObject();//from   www. j  av  a 2 s . c o  m
    generator.flush();
}

From source file:com.attribyte.essem.ESReporter.java

static final void generateMeter(final JsonGenerator generator, final ReportProtos.EssemReport.Meter meter,
        final String application, final String host, final String instance, final long timestamp)
        throws IOException {

    generator.writeStartObject();
    writeStringField(generator, Fields.APPLICATION_FIELD, application);
    writeStringField(generator, Fields.HOST_FIELD, host);
    writeStringField(generator, Fields.INSTANCE_FIELD, instance);
    writeStringField(generator, Fields.NAME_FIELD, meter.getName().trim());
    generator.writeNumberField(Fields.ONE_MINUTE_RATE_FIELD, meter.getOneMinuteRate());
    generator.writeNumberField(Fields.FIVE_MINUTE_RATE_FIELD, meter.getFiveMinuteRate());
    generator.writeNumberField(Fields.FIFTEEN_MINUTE_RATE_FIELD, meter.getFifteenMinuteRate());
    generator.writeNumberField(Fields.MEAN_RATE_FIELD, meter.getMeanRate());
    generator.writeNumberField(Fields.COUNT_FIELD, meter.getCount());
    generator.writeNumberField(Fields.TIMESTAMP_FIELD, timestamp);
    generator.writeEndObject();/*from  w  ww . j  a v  a 2  s  .  co  m*/
    generator.flush();
}

From source file:com.attribyte.essem.ESReporter.java

static final void generateGauge(final JsonGenerator generator, final ReportProtos.EssemReport.Gauge gauge,
        final String application, final String host, final String instance, final long timestamp)
        throws IOException {

    generator.writeStartObject();
    writeStringField(generator, Fields.APPLICATION_FIELD, application);
    writeStringField(generator, Fields.HOST_FIELD, host);
    writeStringField(generator, Fields.INSTANCE_FIELD, instance);
    writeStringField(generator, Fields.NAME_FIELD, gauge.getName().trim());
    if (gauge.hasValue()) {
        generator.writeNumberField(Fields.VALUE_FIELD, gauge.getValue());
    } else if (gauge.hasComment()) {
        generator.writeNumberField(Fields.VALUE_FIELD, 0.0);
        writeStringField(generator, Fields.COMMENT_FIELD, gauge.getComment());
    } else {//from   ww w . j a  v a  2 s. com
        generator.writeNullField(Fields.VALUE_FIELD);
    }

    generator.writeNumberField(Fields.TIMESTAMP_FIELD, timestamp);
    generator.writeEndObject();
    generator.flush();
}

From source file:com.attribyte.essem.ESReporter.java

static final void generateTimer(final JsonGenerator generator, final ReportProtos.EssemReport.Timer timer,
        final String application, final String host, final String instance, final long timestamp)
        throws IOException {

    generator.writeStartObject();
    writeStringField(generator, Fields.APPLICATION_FIELD, application);
    writeStringField(generator, Fields.HOST_FIELD, host);
    writeStringField(generator, Fields.INSTANCE_FIELD, instance);
    writeStringField(generator, Fields.NAME_FIELD, timer.getName().trim());
    generator.writeNumberField(Fields.ONE_MINUTE_RATE_FIELD, timer.getOneMinuteRate());
    generator.writeNumberField(Fields.FIVE_MINUTE_RATE_FIELD, timer.getFiveMinuteRate());
    generator.writeNumberField(Fields.FIFTEEN_MINUTE_RATE_FIELD, timer.getFifteenMinuteRate());
    generator.writeNumberField(Fields.MEAN_RATE_FIELD, timer.getMeanRate());
    generator.writeNumberField(Fields.COUNT_FIELD, timer.getCount());
    generator.writeNumberField(Fields.MAX_FIELD, timer.getMax());
    generator.writeNumberField(Fields.MIN_FIELD, timer.getMin());
    generator.writeNumberField(Fields.MEAN_FIELD, timer.getMean());
    generator.writeNumberField(Fields.P50_FIELD, timer.getMedian());
    generator.writeNumberField(Fields.P75_FIELD, timer.getPercentile75());
    generator.writeNumberField(Fields.P95_FIELD, timer.getPercentile95());
    generator.writeNumberField(Fields.P98_FIELD, timer.getPercentile98());
    generator.writeNumberField(Fields.P99_FIELD, timer.getPercentile99());
    generator.writeNumberField(Fields.P999_FIELD, timer.getPercentile999());
    generator.writeNumberField(Fields.STD_FIELD, timer.getStd());
    generator.writeNumberField(Fields.TIMESTAMP_FIELD, timestamp);
    generator.writeEndObject();//from ww  w .  ja v a  2 s  .  c o m
    generator.flush();
}