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:br.com.hyperclass.snackbar.restapi.serializer.SalesReportSerialize.java

@Override
public void serialize(SalesReportWrapper salesReportWrapper, JsonGenerator jsonGenerator,
        SerializerProvider serializerProvider) throws IOException, JsonProcessingException {

    final Map<Date, List<EventSale>> events = salesReportWrapper.getEventSales();

    jsonGenerator.writeStartObject();

    for (List<EventSale> event : events.values()) {
        eventSale(event, jsonGenerator, serializerProvider);
    }/*from  w w  w.  j a  v a 2 s. c  o  m*/

    jsonGenerator.writeEndObject();

}

From source file:com.cloudmine.api.persistance.CMJacksonModule.java

public CMJacksonModule() {
    super("CustomModule", new Version(1, 0, 0, null));
    addSerializer(new JsonSerializer<Date>() {

        @Override/*from ww w  . j  a  v  a 2 s.  c om*/
        public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider)
                throws IOException, JsonProcessingException {
            jgen.writeStartObject();
            jgen.writeRaw(JsonUtilities.convertDateToUnwrappedJsonClass(value));
            jgen.writeEndObject();
        }

        @Override
        public Class<Date> handledType() {
            return Date.class;
        }
    });

    addDeserializer(Date.class, new JsonDeserializer<Date>() {
        @Override
        public Date deserialize(JsonParser jp, DeserializationContext ctxt)
                throws IOException, JsonProcessingException {
            ObjectMapper mapper = (ObjectMapper) jp.getCodec();
            ObjectNode root = (ObjectNode) mapper.readTree(jp);
            JsonNode classNode = root.get(JsonUtilities.CLASS_KEY);
            boolean isDate = classNode != null && JsonUtilities.DATE_CLASS.equals(classNode.asText());
            if (isDate) {
                JsonNode timeNode = root.get(JsonUtilities.TIME_KEY);
                if (timeNode != null) {
                    Long seconds = timeNode.asLong();
                    Date date = new Date(seconds * 1000);
                    return date;
                }
            }
            return null;
        }
    });
    addSerializer(new JsonSerializer<SimpleCMObject>() {

        @Override
        public void serialize(SimpleCMObject value, JsonGenerator jgen, SerializerProvider provider)
                throws IOException {
            jgen.writeStartObject();
            String json = null;
            try {
                json = value.asUnkeyedObject();
            } catch (ConversionException e) {
                LOG.error("Error while serializing, sending empty json", e);
                json = JsonUtilities.EMPTY_JSON;
            }
            jgen.writeRaw(JsonUtilities.unwrap(json));
            jgen.writeEndObject();
        }

        @Override
        public Class<SimpleCMObject> handledType() {
            return SimpleCMObject.class;
        }
    });

    addSerializer(jsonSerializerForType(CMFile.class));
    addSerializer(jsonSerializerForType(CMSessionToken.class));
    addSerializer(jsonSerializerForType(CMType.class));
    addSerializer(jsonSerializerForType(TransportableString.class));
    addSerializer(jsonSerializerForType(ResponseBase.class));

}

From source file:com.ning.metrics.action.hdfs.data.Row.java

public void toJSON(final JsonGenerator generator) throws IOException {
    int i = 0;/*from  w  w w. j  a  va2 s  .  c om*/
    generator.writeStartObject();
    for (T item : data) {
        generator.writeFieldName(schema.getFieldNameByPosition(i));
        generator.writeObject(getJsonValue(item));
        i++;
    }
    generator.writeEndObject();
    generator.flush();
}

From source file:org.opendaylight.sxp.csit.libraries.DeviceTestLibrary.java

/**
 * @param libraryServer Server where Library will be added
 *//*from  ww w.j a  v a 2s . c o  m*/
public DeviceTestLibrary(RobotLibraryServer libraryServer) {
    super(libraryServer);
    connectionTimers.setReconciliationTime(0);
    connectionTimers.setDeleteHoldDownTime(0);
    pojoBindingsSerializer.registerModule(
            new SimpleModule().addSerializer(SxpBindingFields.class, new JsonSerializer<SxpBindingFields>() {

                @Override
                public void serialize(SxpBindingFields value, JsonGenerator jgen, SerializerProvider provider)
                        throws IOException {
                    jgen.writeStartObject();
                    jgen.writeNumberField("sgt", value.getSecurityGroupTag().getValue());
                    jgen.writeArrayFieldStart("ip-prefix");
                    jgen.writeString(new String(value.getIpPrefix().getValue()));
                    jgen.writeEndArray();
                    jgen.writeEndObject();
                }
            }));
}

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();

    aJG.writeStringField("text", aText);

    aJG.writeFieldName("entities");
    aJG.writeStartArray();//from   w w  w .  ja  v  a2s  .  c  o m
    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();
}

From source file:com.predic8.membrane.core.interceptor.statistics.StatisticsProvider.java

private void writeRecord(ResultSet r, JsonGenerator jsonGen)
        throws IOException, JsonGenerationException, SQLException {
    jsonGen.writeStartObject();
    jsonGen.writeNumberField("statusCode", r.getInt(JDBCUtil.STATUS_CODE));
    jsonGen.writeStringField("time", r.getString(JDBCUtil.TIME));
    jsonGen.writeStringField("rule", r.getString(JDBCUtil.RULE));
    jsonGen.writeStringField("method", r.getString(JDBCUtil.METHOD));
    jsonGen.writeStringField("path", r.getString(JDBCUtil.PATH));
    jsonGen.writeStringField("client", r.getString(JDBCUtil.CLIENT));
    jsonGen.writeStringField("server", r.getString(JDBCUtil.SERVER));
    jsonGen.writeStringField("reqContentType", r.getString(JDBCUtil.REQUEST_CONTENT_TYPE));
    jsonGen.writeNumberField("reqContentLenght", r.getInt(JDBCUtil.REQUEST_CONTENT_LENGTH));
    jsonGen.writeStringField("respContentType", r.getString(JDBCUtil.RESPONSE_CONTENT_TYPE));
    jsonGen.writeNumberField("respContentLenght", r.getInt(JDBCUtil.RESPONSE_CONTENT_LENGTH));
    jsonGen.writeNumberField("duration", r.getInt(JDBCUtil.DURATION));
    jsonGen.writeStringField("msgFilePath", r.getString(JDBCUtil.MSG_FILE_PATH));
    jsonGen.writeEndObject();//from   w  ww . jav a2 s. c om
}

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

public <K, V, D> void serialize(@Nonnull Row<K, V, D> row, @Nonnull JacksonSerializer<? super K> keySerializer,
        @Nonnull JacksonSerializer<? super V> valueSerializer,
        @Nullable JacksonSerializer<? super D> documentSerializer, @Nonnull JsonGenerator generator)
        throws IOException {
    generator.writeStartObject();

    @Nullable/*from   w ww . jav a2s. co m*/
    DocId id = row.getId();
    if (id != null) {
        generator.writeStringField(PROPERTY_ID, id.asString());
    }

    //The key
    generator.writeFieldName(PROPERTY_KEY);
    keySerializer.serialize(row.getKey(), generator);

    //The Value
    generator.writeFieldName(PROPERTY_VALUE);
    V value = row.getValue();
    if (value == null) {
        generator.writeNull();
    } else {
        valueSerializer.serialize(value, generator);
    }

    //The doc
    CouchDoc<? extends D> doc = row.getDoc();
    if (doc != null) {
        if (documentSerializer == null) {
            throw new NullPointerException("documentSerializer must not be null when serializing a doc");
        }

        generator.writeFieldName("doc");
        couchDocSerializer.serialize(doc, documentSerializer, generator);
    }

    generator.writeEndObject();
}

From source file:com.github.pires.example.dal.entities.JSONObjectSerializer.java

private void constructObject(JSONObject object, JsonGenerator jsonGenerator) throws IOException {
    for (String key : JSONObject.getNames(object)) {
        Object value = object.get(key);

        if (value instanceof JSONObject) {
            jsonGenerator.writeFieldName(key);
            jsonGenerator.writeStartObject();
            constructObject(object.getJSONObject(key), jsonGenerator);
            jsonGenerator.writeEndObject();
        } else {/*w  w w .jav a2s.  c om*/
            jsonGenerator.writeStringField(key, value.toString());
        }
    }
}

From source file:com.strategicgains.hyperexpress.serialization.siren.jackson.SirenResourceSerializer.java

private void writeAction(SirenAction action, JsonGenerator jgen) throws IOException {
    if (action == null)
        return;//w ww  .  j a  v  a 2 s  .  com

    jgen.writeStartObject();
    writeClass(action.getClasses(), jgen);
    jgen.writeStringField(NAME, action.getName());
    writeOptionalField("title", action.getTitle(), jgen);
    writeOptionalField(METHOD, action.getMethod(), jgen);
    jgen.writeStringField(HREF, action.getHref());
    writeOptionalField(TYPE, action.getType(), jgen);
    writeFields(action.getFields(), jgen);
    jgen.writeEndObject();
}

From source file:models.ProcessSerializer.java

@Override
public void serialize(Process process, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    jgen.writeStartObject();
    jgen.writeStringField("id", process.getId());
    jgen.writeFieldName("unit");
    jgen.writeObject(process.getUnit());
    jgen.writeFieldName("keywords");
    jgen.writeObject(process.getKeywords());

    jgen.writeFieldName("groups");
    jgen.writeStartArray();/*www .j  ava2s.com*/
    for (Group group : process.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 : process.getUpstreamDerivedRelations()) {
        jgen.writeObject(relation);
    }
    for (DerivedRelation relation : process.getDownstreamDerivedRelations()) {
        jgen.writeObject(relation);
    }
    jgen.writeEndArray();

    jgen.writeFieldName("impacts");
    jgen.writeStartObject();
    for (Impact impact : process.getImpacts().values()) {
        jgen.writeFieldName(impact.getType().getId());
        jgen.writeStartObject();
        jgen.writeFieldName("value");
        jgen.writeObject(impact.getValue());
        jgen.writeFieldName("upstream");
        jgen.writeObject(getUpstreamImpacts(process, impact));
        jgen.writeFieldName("composition");
        jgen.writeObject(getImpactComposition(process, impact));
        jgen.writeEndObject();
    }
    jgen.writeEndObject();

    jgen.writeFieldName("flows");
    jgen.writeStartObject();
    for (ElementaryFlow flow : process.getCalculatedFlows().values()) {
        jgen.writeFieldName(flow.getType().getId());
        jgen.writeStartObject();
        jgen.writeFieldName("value");
        jgen.writeObject(flow.getValue());
        jgen.writeFieldName("upstream");
        jgen.writeObject(getUpstreamFlows(process, flow));
        jgen.writeEndObject();
    }
    jgen.writeEndObject();

    jgen.writeEndObject();
}