Java Code Examples for org.nd4j.shade.jackson.core.JsonGenerator#writeEndArray()

The following examples show how to use org.nd4j.shade.jackson.core.JsonGenerator#writeEndArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataJsonSerializer.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
private void writePoint(JsonGenerator jg, Point p) throws IOException {
    jg.writeStartObject();
    jg.writeFieldName(Data.RESERVED_KEY_POINT_COORDS);
    jg.writeStartArray(p.dimensions());
    for (int i = 0; i < p.dimensions(); i++) {
        writeDouble(jg, p.get(i));
    }
    jg.writeEndArray();

    if(p.label() != null){
        jg.writeFieldName("label");
        jg.writeString(p.label());
    }
    if(p.probability() != null){
        jg.writeFieldName("probability");
        jg.writeNumber(p.probability());
    }

    jg.writeEndObject();
}
 
Example 2
Source File: Configuration.java    From DataVec with Apache License 2.0 6 votes vote down vote up
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] }
 *  It does not output the parameters of the configuration object which is
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration conf, Writer out) throws IOException {
    Configuration config = new Configuration(conf, true);
    config.reloadConfiguration();
    JsonFactory dumpFactory = new JsonFactory();
    JsonGenerator dumpGenerator = dumpFactory.createGenerator(out);
    dumpGenerator.writeStartObject();
    dumpGenerator.writeFieldName("properties");
    dumpGenerator.writeStartArray();
    dumpGenerator.flush();
    for (Map.Entry<Object, Object> item : config.getProps().entrySet()) {
        dumpGenerator.writeStartObject();
        dumpGenerator.writeStringField("key", (String) item.getKey());
        dumpGenerator.writeStringField("value", config.get((String) item.getKey()));
        dumpGenerator.writeBooleanField("isFinal", config.finalParameters.contains(item.getKey()));
        dumpGenerator.writeStringField("resource", config.updatingResource.get(item.getKey()));
        dumpGenerator.writeEndObject();
    }
    dumpGenerator.writeEndArray();
    dumpGenerator.writeEndObject();
    dumpGenerator.flush();
}
 
Example 3
Source File: Configuration.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 *  Writes out all the parameters and their properties (final and resource) to
 *  the given {@link Writer}
 *  The format of the output would be
 *  { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
 *  key2.isFinal,key2.resource}... ] }
 *  It does not output the parameters of the configuration object which is
 *  loaded from an input stream.
 * @param out the Writer to write to
 * @throws IOException
 */
public static void dumpConfiguration(Configuration conf, Writer out) throws IOException {
    Configuration config = new Configuration(conf, true);
    config.reloadConfiguration();
    JsonFactory dumpFactory = new JsonFactory();
    JsonGenerator dumpGenerator = dumpFactory.createGenerator(out);
    dumpGenerator.writeStartObject();
    dumpGenerator.writeFieldName("properties");
    dumpGenerator.writeStartArray();
    dumpGenerator.flush();
    for (Map.Entry<Object, Object> item : config.getProps().entrySet()) {
        dumpGenerator.writeStartObject();
        dumpGenerator.writeStringField("key", (String) item.getKey());
        dumpGenerator.writeStringField("value", config.get((String) item.getKey()));
        dumpGenerator.writeBooleanField("isFinal", config.finalParameters.contains(item.getKey()));
        dumpGenerator.writeStringField("resource", config.updatingResource.get(item.getKey()));
        dumpGenerator.writeEndObject();
    }
    dumpGenerator.writeEndArray();
    dumpGenerator.writeEndObject();
    dumpGenerator.flush();
}
 
Example 4
Source File: VectorSerializer.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(INDArray indArray, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
                throws IOException {
    if (indArray.isView())
        indArray = indArray.dup(indArray.ordering());
    jsonGenerator.writeStartObject();
    DataBuffer view = indArray.data();
    jsonGenerator.writeArrayFieldStart("dataBuffer");
    for (int i = 0; i < view.length(); i++) {
        jsonGenerator.writeNumber(view.getDouble(i));
    }

    jsonGenerator.writeEndArray();

    jsonGenerator.writeArrayFieldStart("shapeField");
    for (int i = 0; i < indArray.rank(); i++) {
        jsonGenerator.writeNumber(indArray.size(i));
    }
    jsonGenerator.writeEndArray();

    jsonGenerator.writeArrayFieldStart("strideField");
    for (int i = 0; i < indArray.rank(); i++)
        jsonGenerator.writeNumber(indArray.stride(i));
    jsonGenerator.writeEndArray();

    jsonGenerator.writeNumberField("offsetField", indArray.offset());
    jsonGenerator.writeStringField("typeField", indArray instanceof IComplexNDArray ? "complex" : "real");
    jsonGenerator.writeNumberField("rankField", indArray.rank());
    jsonGenerator.writeNumberField("numElements", view.length());
    jsonGenerator.writeStringField("orderingField", String.valueOf(indArray.ordering()));
    jsonGenerator.writeEndObject();
}
 
Example 5
Source File: ROCArraySerializer.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ROC[] rocs, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
                throws IOException, JsonProcessingException {
    jsonGenerator.writeStartArray();
    for (ROC r : rocs) {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField("@class", ROC.class.getName());
        serializer.serialize(r, jsonGenerator, serializerProvider);
        jsonGenerator.writeEndObject();
    }
    jsonGenerator.writeEndArray();
}