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

The following examples show how to use org.nd4j.shade.jackson.core.JsonGenerator#writeNumber() . 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: DataJsonSerializer.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static void writeBB(JsonGenerator jg, BoundingBox bb) throws IOException {
    //We'll keep it in the original format, if possible - but encode it as a X/Y format otherwise
    jg.writeStartObject();
    if(bb instanceof BBoxCHW){
        BBoxCHW b = (BBoxCHW)bb;
        jg.writeFieldName(Data.RESERVED_KEY_BB_CX);
        jg.writeNumber(b.cx());
        jg.writeFieldName(Data.RESERVED_KEY_BB_CY);
        jg.writeNumber(b.cy());
        jg.writeFieldName(Data.RESERVED_KEY_BB_H);
        jg.writeNumber(b.h());
        jg.writeFieldName(Data.RESERVED_KEY_BB_W);
        jg.writeNumber(b.w());
    } else {
        jg.writeFieldName(Data.RESERVED_KEY_BB_X1);
        jg.writeNumber(bb.x1());
        jg.writeFieldName(Data.RESERVED_KEY_BB_X2);
        jg.writeNumber(bb.x2());
        jg.writeFieldName(Data.RESERVED_KEY_BB_Y1);
        jg.writeNumber(bb.y1());
        jg.writeFieldName(Data.RESERVED_KEY_BB_Y2);
        jg.writeNumber(bb.y2());
    }
    if(bb.label() != null){
        jg.writeFieldName("label");
        jg.writeString(bb.label());
    }
    if(bb.probability() != null){
        jg.writeFieldName("probability");
        jg.writeNumber(bb.probability());
    }

    jg.writeEndObject();
}
 
Example 3
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 4
Source File: DataJsonSerializer.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
private void writeDouble(JsonGenerator jg, double d) throws IOException {
    jg.writeNumber(d);
}
 
Example 5
Source File: DataJsonSerializer.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
private void writeLong(JsonGenerator jg, long l) throws IOException {
    jg.writeNumber(l);
}
 
Example 6
Source File: JsonSerializerAtomicDouble.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(AtomicDouble atomicDouble, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
    jsonGenerator.writeNumber(atomicDouble.doubleValue());
}
 
Example 7
Source File: JsonSerializerAtomicDouble.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(AtomicDouble atomicDouble, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
    jsonGenerator.writeNumber(atomicDouble.doubleValue());
}