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

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

Introduction

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

Prototype

public void writeStringField(String fieldName, String value) throws IOException, JsonGenerationException 

Source Link

Document

Convenience method for outputting a field entry ("member") that has a String value.

Usage

From source file:com.attribyte.essem.es.TermsAggregation.java

@Override
public void generate(final JsonGenerator generator) throws IOException {
    generator.writeObjectFieldStart(name);
    {/*from  w  w  w  .  j a v  a 2 s  .  co m*/
        generator.writeObjectFieldStart("terms");
        {
            generator.writeStringField("field", field);
            generator.writeNumberField("size", size);
            switch (order) { //Doc count descending is default...
            case DOC_COUNT_ASC:
                generator.writeObjectFieldStart("order");
                generator.writeStringField("_count", "asc");
                generator.writeEndObject();
                break;
            case TERM_ASC:
                generator.writeObjectFieldStart("order");
                generator.writeStringField("_term", "asc");
                generator.writeEndObject();
                break;
            case TERM_DESC:
                generator.writeObjectFieldStart("order");
                generator.writeStringField("_term", "desc");
                generator.writeEndObject();
                break;
            }
        }
        generator.writeEndObject();
        if (subs != null && subs.size() > 0) {
            generator.writeObjectFieldStart(AGGREGATION_OBJECT_NAME);
            for (Aggregation sub : subs) {
                sub.generate(generator);
            }
            generator.writeEndObject();
        }
    }
    generator.writeEndObject();
}

From source file:com.cedarsoft.serialization.serializers.jackson.ExtensionSerializer.java

@Override
public void serialize(@Nonnull JsonGenerator serializeTo, @Nonnull Extension object,
        @Nonnull Version formatVersion) throws IOException, JsonProcessingException {
    verifyVersionReadable(formatVersion);
    //delimiter//from w w w .j  av a  2 s .  c  o  m
    serializeTo.writeStringField(PROPERTY_DELIMITER, object.getDelimiter());
    //extension
    serializeTo.writeStringField(PROPERTY_EXTENSION, object.getExtension());
}

From source file:org.pentaho.metaverse.impl.model.kettle.json.AbstractMetaJsonSerializer.java

@Override
public void serialize(T meta, JsonGenerator json, SerializerProvider serializerProvider)
        throws IOException, JsonGenerationException {

    json.writeStartObject();// w  w w  .j  av a  2  s  .com
    json.writeStringField(IInfo.JSON_PROPERTY_CLASS, meta.getClass().getName());
    json.writeStringField(IInfo.JSON_PROPERTY_NAME, meta.getName());
    json.writeStringField(IInfo.JSON_PROPERTY_DESCRIPTION, meta.getDescription());
    json.writeObjectField(JSON_PROPERTY_CREATED_DATE, meta.getCreatedDate());
    json.writeObjectField(JSON_PROPERTY_LAST_MODIFIED_DATE, meta.getModifiedDate());
    json.writeStringField(JSON_PROPERTY_CREATED_BY, meta.getCreatedUser());
    json.writeStringField(JSON_PROPERTY_LAST_MODIFIED_BY, meta.getModifiedUser());
    json.writeStringField(JSON_PROPERTY_PATH, meta.getFilename());
    if (meta.getRepository() != null) {
        json.writeStringField(JSON_PROPERTY_REPOSITORY, meta.getRepository().getName());
    }

    serializeParameters(meta, json);
    serializeVariables(meta, json);
    serializeSteps(meta, json);
    serializeConnections(meta, json);
    serializeHops(meta, json);

    json.writeEndObject();
}

From source file:org.talend.daikon.exception.TalendRuntimeException.java

/**
 * Describe this error in json into the given writer.
 * /*from w  w w . ja v  a  2 s . c o m*/
 * @param writer where to write this error.
 */
public void writeTo(Writer writer) {
    try {
        JsonGenerator generator = (new JsonFactory()).createGenerator(writer);
        generator.writeStartObject();
        {
            generator.writeStringField("code", //$NON-NLS-1$
                    code.getProduct() + '_' + code.getGroup() + '_' + code.getCode());
            generator.writeStringField("message", code.getCode()); //$NON-NLS-1$
            if (cause != null) {
                generator.writeStringField("cause", cause.getMessage()); //$NON-NLS-1$
            }
            if (context != null) {
                generator.writeFieldName("context"); //$NON-NLS-1$
                generator.writeStartObject();
                for (Map.Entry<String, Object> entry : context.entries()) {
                    generator.writeStringField(entry.getKey(), entry.getValue().toString());
                }
                generator.writeEndObject();
            }
        }
        generator.writeEndObject();
        generator.flush();
    } catch (IOException e) {
        LOGGER.error("Unable to write exception to " + writer + ".", e);
    }
}

From source file:org.n52.ar.layar.LayarResponse.java

public void toJSON(final JsonGenerator generator) throws IOException {
    generator.writeStartObject();/*w  ww  . j  a  v  a 2s  . com*/

    /*
     * mandatory:
     */
    generator.writeStringField("layer", this.layer);
    if (this.errorCode != CODE_ERROR && this.hotspots.size() < 1) {
        this.errorString = "No POI found. Please increase the search range to try again.";
        this.errorCode = CODE_ERROR;
    }
    generator.writeStringField("errorString", this.errorString);
    generator.writeNumberField("errorCode", this.errorCode);

    // paging is not implemented yet
    generator.writeBooleanField("morePages", this.morePages);
    if (this.nextPageKey != null) {
        generator.writeStringField("nextPageKey", this.nextPageKey);
    } else {
        generator.writeNullField("nextPageKey");
    }
    // generator.writeNumberField("refreshInterval", 3600);
    // generator.writeNumberField("refreshDistance", 50);
    // generator.writeBooleanField("fullRefresh", false);
    // actions for the entire layer: http://layar.com/documentation/browser/api/getpois-response/actions/
    if (this.errorCode == CODE_OK)
        this.showMessage = "You got " + this.hotspots.size() + " hits in the area around you!";
    generator.writeStringField("showMessage", this.showMessage);
    // deletedHotspots
    // animations
    // showDialog: title, description, iconURL, actions
    generator.writeNullField("biwStyle");

    /*
     * hotspots (mandatory):
     */
    createHotspots(generator);

    generator.writeEndObject();
}

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. ja  v a2s  .  co 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:com.cedarsoft.serialization.jackson.test.RoleSerializer.java

@Override
public void serialize(@Nonnull JsonGenerator serializeTo, @Nonnull Role object, @Nonnull Version formatVersion)
        throws IOException, VersionException, JsonProcessingException {
    serializeTo.writeNumberField(PROPERTY_ID, object.getId());
    serializeTo.writeStringField(PROPERTY_DESCRIPTION, object.getDescription());
}

From source file:com.microsoft.azure.storage.blob.BlobEncryptionData.java

public String serialize() throws IOException {

    final StringWriter strWriter = new StringWriter();
    JsonGenerator generator = Utility.getJsonGenerator(strWriter);

    try {//  www  .  j  a  va 2 s  .  c o m
        // start object
        generator.writeStartObject();

        // write the encryption mode
        generator.writeStringField(Constants.EncryptionConstants.ENCRYPTION_MODE,
                Constants.EncryptionConstants.FULL_BLOB);

        // write the encryption data
        this.serialize(generator);

        // end object
        generator.writeEndObject();
    } finally {
        generator.close();
    }

    return strWriter.toString();
}

From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.api.LiveEndpointsController.java

private Response liveEndpoints(final String forTool, final int limit) {
    final List<CassandraFrameworkProtos.CassandraNode> liveNodes = cluster.liveNodes(limit);

    if (liveNodes.isEmpty()) {
        return Response.status(400).build();
    }//from w w  w  .j a  v  a  2s  .co m

    final CassandraFrameworkProtos.CassandraFrameworkConfiguration configuration = cluster.getConfiguration()
            .get();

    final int nativePort = CassandraCluster.getPortMapping(configuration, CassandraCluster.PORT_NATIVE);
    final int rpcPort = CassandraCluster.getPortMapping(configuration, CassandraCluster.PORT_RPC);
    final int jmxPort = CassandraCluster.getPortMapping(configuration, CassandraCluster.PORT_JMX);

    final CassandraFrameworkProtos.CassandraNode first = liveNodes.get(0);

    try {
        switch (forTool) {
        case "cqlsh":
            // return a string: "HOST PORT"
            return Response.ok(first.getIp() + ' ' + nativePort).build();
        case "stress":
            // cassandra-stress options:
            // -node NODE1,NODE2,...
            // -port [native=NATIVE_PORT] [thrift=THRIFT_PORT] [jmx=JMX_PORT]
            final StringBuilder sb = new StringBuilder();
            sb.append("-node ");
            for (int i = 0; i < liveNodes.size(); i++) {
                if (i > 0) {
                    sb.append(',');
                }
                sb.append(liveNodes.get(i).getIp());
            }
            sb.append(" -port native=").append(nativePort).append(" thrift=").append(rpcPort).append(" jmx=")
                    .append(jmxPort);
            return Response.ok(sb.toString()).build();
        case "nodetool":
            // nodetool options:
            // -h HOST
            // -p JMX_PORT
            return Response
                    .ok("-h " + first.getJmxConnect().getIp() + " -p " + first.getJmxConnect().getJmxPort())
                    .build();
        case "json":
            // produce a simple JSON with the native port and live node IPs
            return JaxRsUtils.buildStreamingResponse(factory, new StreamingJsonResponse() {
                @Override
                public void write(final JsonGenerator json) throws IOException {
                    json.writeStringField("clusterName", configuration.getFrameworkName());
                    json.writeNumberField("nativePort", nativePort);
                    json.writeNumberField("rpcPort", rpcPort);
                    json.writeNumberField("jmxPort", jmxPort);

                    json.writeArrayFieldStart("liveNodes");
                    for (final CassandraFrameworkProtos.CassandraNode liveNode : liveNodes) {
                        json.writeString(liveNode.getIp());
                    }
                    json.writeEndArray();
                }
            });
        case "text":
            // produce a simple text with the native port in the first line and one line per live node IP
            return JaxRsUtils.buildStreamingResponse(Response.Status.OK, "text/plain",
                    new StreamingTextResponse() {
                        @Override
                        public void write(final PrintWriter pw) {
                            pw.println("NATIVE: " + nativePort);
                            pw.println("RPC: " + rpcPort);
                            pw.println("JMX: " + jmxPort);
                            for (final CassandraFrameworkProtos.CassandraNode liveNode : liveNodes) {
                                pw.println("IP: " + liveNode.getIp());
                            }
                        }
                    });
        }

        return Response.status(404).build();
    } catch (final Exception e) {
        LOGGER.error("Failed to all nodes list", e);
        return Response.serverError().build();
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.brat.internal.model.BratAnnotationDocument.java

public void write(JsonGenerator aJG, String aText) throws IOException {
    aJG.writeStartObject();//from w  w  w  .  ja v  a 2 s .  co  m

    aJG.writeStringField("text", aText);

    aJG.writeFieldName("entities");
    aJG.writeStartArray();
    for (BratAnnotation ann : annotations.values()) {
        if (ann instanceof BratTextAnnotation) {
            ann.write(aJG);
        }
    }
    aJG.writeEndArray();

    aJG.writeFieldName("relations");
    aJG.writeStartArray();
    for (BratAnnotation ann : annotations.values()) {
        if (ann instanceof BratRelationAnnotation) {
            ann.write(aJG);
        }
    }
    aJG.writeEndArray();

    aJG.writeFieldName("triggers");
    aJG.writeStartArray();
    for (BratAnnotation ann : annotations.values()) {
        if (ann instanceof BratEventAnnotation) {
            ((BratEventAnnotation) ann).getTriggerAnnotation().write(aJG);
        }
    }
    aJG.writeEndArray();

    aJG.writeFieldName("events");
    aJG.writeStartArray();
    for (BratAnnotation ann : annotations.values()) {
        if (ann instanceof BratEventAnnotation) {
            ann.write(aJG);
        }
    }
    aJG.writeEndArray();

    aJG.writeFieldName("attributes");
    aJG.writeStartArray();
    for (BratAnnotation ann : annotations.values()) {
        for (BratAttribute attr : ann.getAttributes()) {
            attr.write(aJG);
        }
    }
    aJG.writeEndArray();

    aJG.writeEndObject();
}