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

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

Introduction

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

Prototype

public abstract void writeStartArray() throws IOException, JsonGenerationException;

Source Link

Document

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

Usage

From source file:bz.tsung.jsonapi4j.JsonApiSerializer.java

@Override
public void serialize(T object, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException {
    if (object instanceof Set) {
        jsonGenerator.writeStartArray();
        for (Object value : (Set) object) {
            jsonGenerator.writeObject(value);
        }/* w ww.j  a va  2s. c  o  m*/
        jsonGenerator.writeEndArray();
    } else {
        jsonGenerator.writeObject(object);
    }
}

From source file:br.com.hyperclass.snackbar.restapi.serializer.ProductsSerializer.java

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

    jsonGenerator.writeStartArray();

    for (final Product product : productsWrapper.getProducts()) {
        productSerializer.serialize(product, jsonGenerator);
    }/*ww w.  ja va 2 s  .c om*/

    jsonGenerator.writeEndArray();

}

From source file:org.lamop.riche.model.jsonserialize.RelationWorkSourceSerialize.java

@Override
public void serialize(List<RelationWorkSource> list, JsonGenerator jg, SerializerProvider sp)
        throws IOException, JsonProcessingException {

    jg.writeStartArray();

    List<RelationWorkSource> aSerialiser = new ArrayList<>();
    for (int i = 0; i < list.size(); i++) {
        RelationWorkSource get = list.get(i);
        RelationWorkSource newtruc = new RelationWorkSource();
        newtruc.setSource(get.getSource());
        newtruc.setNote(get.getNote());/*from ww  w  . j  a va2s.com*/
        newtruc.setExtract(get.getExtract());
        aSerialiser.add(newtruc);
    }

    for (int i = 0; i < aSerialiser.size(); i++) {
        RelationWorkSource get = aSerialiser.get(i);
        jg.writeObject(get);
    }

    //         for (int i = 0; i < list.size(); i++) {
    //            RelationWorkSource get = list.get(i);
    //            
    ////            jg.writeObject(get.getSource());
    ////            
    //        }
    jg.writeEndArray();
    //        jg.write

    //        jg.writeObjectField("source", t.getSource());
    //        jg.writeNumberField("id", t.getId());
    //        jg.writeEndObject();

}

From source file:io.airlift.event.client.JsonEventWriter.java

public <T> void writeEvents(EventClient.EventGenerator<T> events, OutputStream out) throws IOException {
    Preconditions.checkNotNull(events, "events is null");
    Preconditions.checkNotNull(out, "out is null");

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

    jsonGenerator.writeStartArray();

    events.generate(new EventClient.EventPoster<T>() {
        @Override/*from  w ww  . j  av a2s . c  o  m*/
        public void post(T event) throws IOException {
            JsonSerializer<T> serializer = getSerializer(event);
            if (serializer == null) {
                throw new InvalidEventException("Event class [%s] has not been registered as an event",
                        event.getClass().getName());
            }

            serializer.serialize(event, jsonGenerator, null);
        }
    });

    jsonGenerator.writeEndArray();
    jsonGenerator.flush();
}

From source file:com.netflix.spectator.tdigest.Json.java

/** Encode the measurements using the generator. */
void encode(Map<String, String> commonTags, List<TDigestMeasurement> ms, JsonGenerator gen) throws IOException {
    gen.writeStartArray();
    for (TDigestMeasurement m : ms) {
        encode(commonTags, m, gen);//ww w  . j a  va  2s. c o m
    }
    gen.writeEndArray();
}

From source file:org.eclipse.winery.repository.resources.entitytypes.relationshiptypes.ImplementationsOfOneRelationshipTypeResource.java

/**
 * required by implementations.jsp//  www  .  jav  a  2s.  c  o m
 *
 * Method similar top the one of ImplementationsOfOneNodeTypeResource
 *
 * @return for each node type implementation implementing the associated
 *         node type
 */
@Override
public String getImplementationsTableData() {
    String res;
    JsonFactory jsonFactory = new JsonFactory();
    StringWriter tableDataSW = new StringWriter();
    try {
        JsonGenerator jGenerator = jsonFactory.createGenerator(tableDataSW);
        jGenerator.writeStartArray();

        Collection<RelationshipTypeImplementationId> allNTIids = BackendUtils
                .getAllElementsRelatedWithATypeAttribute(RelationshipTypeImplementationId.class,
                        this.getTypeId().getQName());
        for (RelationshipTypeImplementationId ntiID : allNTIids) {
            jGenerator.writeStartArray();
            jGenerator.writeString(ntiID.getNamespace().getDecoded());
            jGenerator.writeString(ntiID.getXmlId().getDecoded());
            jGenerator.writeEndArray();
        }
        jGenerator.writeEndArray();
        jGenerator.close();
        tableDataSW.close();
        res = tableDataSW.toString();
    } catch (Exception e) {
        ImplementationsOfOneRelationshipTypeResource.LOGGER.error(e.getMessage(), e);
        res = "[]";
    }
    return res;
}

From source file:org.example.testcases.BasicTypeArraysSerializer.java

private void writeArray_int(JsonGenerator jg, int[] array) throws IOException {
    jg.writeStartArray();
    for (int val : array) {
        jg.writeNumber(val);
    }/*  w w w  . ja va2s .co  m*/
    jg.writeEndArray();
}

From source file:org.example.testcases.BasicTypeArraysSerializer.java

private void writeArray_char(JsonGenerator jg, char[] array) throws IOException {
    jg.writeStartArray();
    for (char val : array) {
        jg.writeObject(val);
    }// w w  w  .ja  v a 2 s. co  m
    jg.writeEndArray();
}

From source file:org.example.testcases.BasicTypeArraysSerializer.java

private void writeArray_byte(JsonGenerator jg, byte[] array) throws IOException {
    jg.writeStartArray();
    for (byte val : array) {
        jg.writeNumber(val);
    }//from  w ww.jav a  2  s.c  o  m
    jg.writeEndArray();
}

From source file:org.example.testcases.BasicTypeArraysSerializer.java

private void writeArray_float(JsonGenerator jg, float[] array) throws IOException {
    jg.writeStartArray();
    for (float val : array) {
        jg.writeNumber(val);
    }// ww  w .  j av a 2 s  .  c o  m
    jg.writeEndArray();
}