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

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

Introduction

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

Prototype

public abstract void writeEndObject() throws IOException, JsonGenerationException;

Source Link

Document

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

Usage

From source file:com.hpcloud.mon.resource.serialization.SubAlarmExpressionSerializer.java

@Override
public void serialize(AlarmSubExpression value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    jgen.writeStartObject();/*from   w  ww  .j  av a2  s . c  o  m*/
    jgen.writeStringField("function", value.getFunction().name());
    jgen.writeStringField("metric_name", value.getMetricDefinition().name);
    jgen.writeObjectField("dimensions", value.getMetricDefinition().dimensions == null ? Collections.emptyMap()
            : value.getMetricDefinition().dimensions);
    jgen.writeStringField("operator", value.getOperator().name());
    jgen.writeNumberField("threshold", value.getThreshold());
    jgen.writeNumberField("period", value.getPeriod());
    jgen.writeNumberField("periods", value.getPeriods());
    jgen.writeEndObject();
}

From source file:org.createnet.raptor.models.objects.serializer.ServiceObjectSerializer.java

@Override
public void serialize(ServiceObject t, JsonGenerator jg, SerializerProvider sp) throws IOException {

    jg.writeStartObject();//from w w  w. ja va2s.  c om

    if (t.id != null) {
        jg.writeStringField("id", t.id);
    }

    if (t.userId != null) {
        jg.writeStringField("userId", t.userId);
    }

    if (t.name != null) {
        jg.writeStringField("name", t.name);
    }

    if (t.description != null) {
        jg.writeStringField("description", t.description);
    }

    jg.writeObjectField("streams", t.streams);
    jg.writeObjectField("actions", t.actions);

    jg.writeObjectField("customFields", t.customFields);
    jg.writeObjectField("settings", t.settings);

    jg.writeEndObject();

}

From source file:net.opentsdb.tree.Leaf.java

/**
 * Writes the leaf to a JSON object for storage. This is necessary for the CAS
 * calls and to reduce storage costs since we don't need to store UID names
 * (particularly as someone may rename a UID)
 * @return The byte array to store//w ww .  j a va2  s .co m
 */
private byte[] toStorageJson() {
    final ByteArrayOutputStream output = new ByteArrayOutputStream(display_name.length() + tsuid.length() + 30);
    try {
        final JsonGenerator json = JSON.getFactory().createGenerator(output);

        json.writeStartObject();

        // we only need to write a small amount of information
        json.writeObjectField("displayName", display_name);
        json.writeObjectField("tsuid", tsuid);

        json.writeEndObject();
        json.close();

        // TODO zero copy?
        return output.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:net.opentsdb.contrib.tsquare.web.view.GraphiteJsonResponseWriter.java

@Override
public void write(final AnnotatedDataPoints annotatedPoints, final ResponseContext context) throws IOException {
    final JsonGenerator jsonGenerator = getJsonGenerator(context);

    jsonGenerator.writeStartObject();/*from w w w. ja va2 s .  c  o  m*/
    jsonGenerator.writeStringField("target", annotatedPoints.getDataPoints().metricName());

    if (includeAllTags) {
        jsonGenerator.writeArrayFieldStart("tags");
        for (final Map.Entry<String, String> entry : annotatedPoints.getDataPoints().getTags().entrySet()) {
            jsonGenerator.writeStartObject();
            jsonGenerator.writeStringField("key", entry.getKey());
            jsonGenerator.writeStringField("value", entry.getValue());
            jsonGenerator.writeEndObject();
        }
        jsonGenerator.writeEndArray();
    }

    if (includeAggregatedTags) {
        jsonGenerator.writeArrayFieldStart("aggregatedTags");
        for (final String tag : annotatedPoints.getDataPoints().getAggregatedTags()) {
            jsonGenerator.writeString(tag);
        }
        jsonGenerator.writeEndArray();
    }

    if (summarize) {
        final DataPointsAsDoubles doubles = new DataPointsAsDoubles(annotatedPoints.getDataPoints());
        final double aggValue = Aggregators.SUM.runDouble(doubles);
        jsonGenerator.writeNumberField("summarizedValue", aggValue);
    } else {
        jsonGenerator.writeArrayFieldStart("datapoints");

        for (final DataPoint p : annotatedPoints.getDataPoints()) {
            jsonGenerator.writeStartArray();

            if (p.isInteger()) {
                jsonGenerator.writeNumber(p.longValue());
            } else {
                jsonGenerator.writeNumber(p.doubleValue());
            }

            if (isMillisecondResolution()) {
                jsonGenerator.writeNumber(p.timestamp());
            } else {
                jsonGenerator.writeNumber(TimeUnit.MILLISECONDS.toSeconds(p.timestamp()));
            }

            jsonGenerator.writeEndArray();
        }

        jsonGenerator.writeEndArray();
    }

    jsonGenerator.writeEndObject();
}

From source file:com.predic8.membrane.core.interceptor.administration.AdminRESTInterceptor.java

@Mapping("/admin/rest/exchanges/(-?\\d+)/(response|request)/header")
public Response getRequestHeader(QueryParameter params, String relativeRootPath) throws Exception {
    final AbstractExchange exc = router.getExchangeStore().getExchangeById(params.getGroupInt(1));

    if (exc == null) {
        return Response.notFound().build();
    }//from   w w w.  j  a v a2  s .co m

    final Message msg = params.getGroup(2).equals("response") ? exc.getResponse() : exc.getRequest();

    if (msg == null) {
        return Response.noContent().build();
    }

    return json(new JSONContent() {
        public void write(JsonGenerator gen) throws Exception {
            gen.writeStartObject();
            gen.writeArrayFieldStart("headers");
            for (HeaderField hf : msg.getHeader().getAllHeaderFields()) {
                gen.writeStartObject();
                gen.writeStringField("name", hf.getHeaderName().toString());
                gen.writeStringField("value", hf.getValue());
                gen.writeEndObject();
            }
            gen.writeEndArray();
            gen.writeEndObject();
        }
    });
}

From source file:org.calrissian.mango.json.ser.NodeSerializer.java

public void serialize(Leaf node, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
        throws IOException {

    if (node instanceof EqualsLeaf) {
        //eq//  ww  w. j av  a 2s .com
        jsonGenerator.writeObjectFieldStart("eq");
        EqualsLeaf equalsLeaf = (EqualsLeaf) node;
        jsonGenerator.writeStringField("key", equalsLeaf.getKey());

        Object value = equalsLeaf.getValue();
        String type = typeRegistry.getAlias(value);
        String val_str = typeRegistry.encode(value);
        jsonGenerator.writeStringField("type", type);
        jsonGenerator.writeStringField("value", val_str);

        jsonGenerator.writeEndObject();
    } else if (node instanceof NotEqualsLeaf) {
        //neq
        NotEqualsLeaf leaf = (NotEqualsLeaf) node;
        jsonGenerator.writeObjectFieldStart("neq");
        jsonGenerator.writeStringField("key", leaf.getKey());

        Object value = leaf.getValue();
        String type = typeRegistry.getAlias(value);
        String val_str = typeRegistry.encode(value);
        jsonGenerator.writeStringField("type", type);
        jsonGenerator.writeStringField("value", val_str);

        jsonGenerator.writeEndObject();
    } else if (node instanceof RangeLeaf) {
        //range
        RangeLeaf leaf = (RangeLeaf) node;
        jsonGenerator.writeObjectFieldStart("range");
        jsonGenerator.writeStringField("key", leaf.getKey());

        Object start = leaf.getStart();
        String type = typeRegistry.getAlias(start);
        String val_str = typeRegistry.encode(start);
        jsonGenerator.writeStringField("type", type);
        jsonGenerator.writeStringField("start", val_str);

        Object end = leaf.getEnd();
        val_str = typeRegistry.encode(end);
        jsonGenerator.writeStringField("end", val_str);

        jsonGenerator.writeEndObject();
    } else
        throw new IllegalArgumentException("Unsupported leaf: " + node);

}

From source file:net.solarnetwork.node.upload.bulkjsonwebpost.InstructionSerializer.java

@Override
public void serialize(Instruction instruction, JsonGenerator generator, SerializerProvider provider)
        throws IOException, JsonGenerationException {
    if (instruction.getTopic() == null || instruction.getStatus() == null) {
        return;/*from  w w  w .  j a v  a  2 s.c o  m*/
    }
    generator.writeStartObject();
    generator.writeStringField("__type__", "InstructionStatus");
    if (instruction.getId() != null) {
        generator.writeStringField("id", instruction.getId().toString());
    }
    generator.writeStringField("instructionId", instruction.getRemoteInstructionId());
    generator.writeStringField("topic", instruction.getTopic());
    generator.writeStringField("status", instruction.getStatus().getInstructionState().toString());
    generator.writeEndObject();
}

From source file:org.neo4j.ontology.server.unmanaged.AnnotationResource.java

private void writeJsonNodeObjectifiedObjectParents(JsonGenerator jg, Node term, Label annotationLabel)
        throws IOException {
    jg.writeFieldName("parents"); // parents:
    jg.writeStartObject(); // {
    for (Relationship subClassOf : term.getRelationships(SUBCLASS_OF, OUTGOING)) {
        if (subClassOf.getEndNode().hasLabel(annotationLabel)) {
            jg.writeBooleanField(subClassOf.getEndNode().getProperty("uri").toString(), true);
        }/*from   w  w  w. j  a va 2s .c  o  m*/
    }
    jg.writeEndObject(); // }
}

From source file:models.CoefficientSerializer.java

@Override
public void serialize(Coefficient coefficient, JsonGenerator jgen, SerializerProvider provider)
        throws IOException {
    jgen.writeStartObject();//from  ww  w.ja  v a  2s .  c o  m
    jgen.writeStringField("id", coefficient.getId());
    jgen.writeFieldName("unit");
    jgen.writeObject(coefficient.getUnit());
    jgen.writeFieldName("keywords");
    jgen.writeObject(coefficient.getKeywords());
    jgen.writeFieldName("value");
    jgen.writeObject(coefficient.getValue());

    jgen.writeFieldName("groups");
    jgen.writeStartArray();
    for (Group group : coefficient.getGroups()) {
        jgen.writeStartObject();
        jgen.writeStringField("id", group.getId());
        jgen.writeStringField("label", group.getLabel());
        jgen.writeEndObject();
    }
    jgen.writeEndArray();

    jgen.writeFieldName("relations");
    jgen.writeStartArray();
    for (DerivedRelation relation : coefficient.getDerivedRelations()) {
        jgen.writeObject(relation);
    }
    jgen.writeEndArray();
    jgen.writeEndObject();
}