Java Code Examples for org.nd4j.shade.jackson.core.JsonGenerator#writeStringField()
The following examples show how to use
org.nd4j.shade.jackson.core.JsonGenerator#writeStringField() .
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: Configuration.java From DataVec with Apache License 2.0 | 6 votes |
/** * 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 2
Source File: Configuration.java From deeplearning4j with Apache License 2.0 | 6 votes |
/** * 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: FixedValueSerializer.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Override public void serialize(FixedValue fixedValue, JsonGenerator j, SerializerProvider serializerProvider) throws IOException { Object o = fixedValue.getValue(); j.writeStringField("@valueclass", o.getClass().getName()); if(o instanceof Number || o instanceof String || o instanceof Enum){ j.writeObjectField("value", o); } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o); baos.close(); byte[] b = baos.toByteArray(); String base64 = new Base64().encodeToString(b); j.writeStringField("data", base64); } }
Example 4
Source File: TDigestSerializer.java From DataVec with Apache License 2.0 | 5 votes |
@Override public void serialize(TDigest td, JsonGenerator j, SerializerProvider sp) throws IOException, JsonProcessingException { try(ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos)){ oos.writeObject(td); oos.close(); byte[] bytes = baos.toByteArray(); Base64 b = new Base64(); String str = b.encodeAsString(bytes); j.writeStartObject(); j.writeStringField("digest", str); j.writeEndObject(); } }
Example 5
Source File: DateTimeFieldTypeSerializer.java From DataVec with Apache License 2.0 | 5 votes |
@Override public void serialize(DateTimeFieldType dateTimeFieldType, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("fieldType", dateTimeFieldType.getName()); jsonGenerator.writeEndObject(); }
Example 6
Source File: VectorSerializer.java From nd4j with Apache License 2.0 | 5 votes |
@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 7
Source File: NDArraySerializer.java From nd4j with Apache License 2.0 | 5 votes |
@Override public void serialize(INDArray indArray, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { String toBase64 = Nd4jBase64.base64String(indArray); jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("array", toBase64); jsonGenerator.writeEndObject(); }
Example 8
Source File: TDigestSerializer.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public void serialize(TDigest td, JsonGenerator j, SerializerProvider sp) throws IOException, JsonProcessingException { try(ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos)){ oos.writeObject(td); oos.close(); byte[] bytes = baos.toByteArray(); Base64 b = new Base64(); String str = b.encodeAsString(bytes); j.writeStartObject(); j.writeStringField("digest", str); j.writeEndObject(); } }
Example 9
Source File: DateTimeFieldTypeSerializer.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public void serialize(DateTimeFieldType dateTimeFieldType, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("fieldType", dateTimeFieldType.getName()); jsonGenerator.writeEndObject(); }
Example 10
Source File: ROCArraySerializer.java From deeplearning4j with Apache License 2.0 | 5 votes |
@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(); }
Example 11
Source File: NDArraySerializer.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public void serialize(INDArray indArray, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { String toBase64 = Nd4jBase64.base64String(indArray); jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("array", toBase64); jsonGenerator.writeEndObject(); }