@Override public void serialize(Map<FlowEntryTuple, SwitchPortStatistics> portStats, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.configure(Feature.WRITE_NUMBERS_AS_STRINGS,true); jsonGenerator.writeStartObject(); for(Map.Entry<FlowEntryTuple,SwitchPortStatistics> portStatsEntry : portStats.entrySet()){ jsonGenerator.writeStringField("srcAddr",portStatsEntry.getKey().getSrcAddr().toString()); jsonGenerator.writeStringField("dstAddr",portStatsEntry.getKey().getDstAddr().toString()); jsonGenerator.writeStringField("srcOFPort",portStatsEntry.getKey().getSrcPort().toString()); jsonGenerator.writeStringField("dstOFPort",portStatsEntry.getKey().getDstPort().toString()); jsonGenerator.writeStringField("prot", String.valueOf(portStatsEntry.getKey().getProt())); jsonGenerator.writeStringField("tos", String.valueOf(portStatsEntry.getKey().getTos())); jsonGenerator.writeStringField("input",String.valueOf(portStatsEntry.getKey().getInput())); jsonGenerator.writeStringField("pkts", String.valueOf(portStatsEntry.getValue().getPkts())); jsonGenerator.writeStringField("octs", String.valueOf(portStatsEntry.getValue().getOcts())); jsonGenerator.writeStringField("first", String.valueOf(portStatsEntry.getValue().getFirst())); jsonGenerator.writeStringField("last", String.valueOf(portStatsEntry.getValue().getLast())); jsonGenerator.writeStringField("tcpFlags", String.valueOf(portStatsEntry.getValue().getTcpflags())); jsonGenerator.writeStringField("drops", String.valueOf(portStatsEntry.getValue().getDrops())); } jsonGenerator.writeEndObject(); }
private void init() throws IOException { JsonFactory factory = new JsonFactory(); factory.configure(Feature.AUTO_CLOSE_TARGET, false); generator = factory.createGenerator(writer); if (prettyPrint) { if (prettyPrinter == null) { prettyPrinter = new JCalPrettyPrinter(); } generator.setPrettyPrinter(prettyPrinter); } if (wrapInArray) { generator.writeStartArray(); } }
protected final void _writePPFieldName(SerializableString paramSerializableString, boolean paramBoolean) { if (paramBoolean) this._cfgPrettyPrinter.writeObjectEntrySeparator(this); else this._cfgPrettyPrinter.beforeObjectEntries(this); char[] arrayOfChar1 = paramSerializableString.asQuotedChars(); if (isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES)) { if (this._outputTail >= this._outputEnd) _flushBuffer(); char[] arrayOfChar2 = this._outputBuffer; int i = this._outputTail; this._outputTail = (i + 1); arrayOfChar2[i] = '"'; writeRaw(arrayOfChar1, 0, arrayOfChar1.length); if (this._outputTail >= this._outputEnd) _flushBuffer(); char[] arrayOfChar3 = this._outputBuffer; int j = this._outputTail; this._outputTail = (j + 1); arrayOfChar3[j] = '"'; return; } writeRaw(arrayOfChar1, 0, arrayOfChar1.length); }
protected final void _writePPFieldName(String paramString, boolean paramBoolean) { if (paramBoolean) this._cfgPrettyPrinter.writeObjectEntrySeparator(this); else this._cfgPrettyPrinter.beforeObjectEntries(this); if (isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES)) { if (this._outputTail >= this._outputEnd) _flushBuffer(); char[] arrayOfChar1 = this._outputBuffer; int i = this._outputTail; this._outputTail = (i + 1); arrayOfChar1[i] = '"'; _writeString(paramString); if (this._outputTail >= this._outputEnd) _flushBuffer(); char[] arrayOfChar2 = this._outputBuffer; int j = this._outputTail; this._outputTail = (j + 1); arrayOfChar2[j] = '"'; return; } _writeString(paramString); }
public final void close() { super.close(); if ((this._outputBuffer != null) && (isEnabled(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT))) while (true) { JsonWriteContext localJsonWriteContext = getOutputContext(); if (localJsonWriteContext.inArray()) { writeEndArray(); } else { if (!localJsonWriteContext.inObject()) break; writeEndObject(); } } _flushBuffer(); if (this._writer != null) if ((this._ioContext.isResourceManaged()) || (isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET))) this._writer.close(); else if (isEnabled(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM)) this._writer.flush(); _releaseBuffers(); }
public void close() { super.close(); if ((this._outputBuffer != null) && (isEnabled(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT))) while (true) { JsonWriteContext localJsonWriteContext = getOutputContext(); if (localJsonWriteContext.inArray()) { writeEndArray(); } else { if (!localJsonWriteContext.inObject()) break; writeEndObject(); } } _flushBuffer(); if (this._outputStream != null) if ((this._ioContext.isResourceManaged()) || (isEnabled(JsonGenerator.Feature.AUTO_CLOSE_TARGET))) this._outputStream.close(); else if (isEnabled(JsonGenerator.Feature.FLUSH_PASSED_TO_STREAM)) this._outputStream.flush(); _releaseBuffers(); }
private static String generateJson(Object o, boolean prettyPrint, boolean escapeNonASCII) { try { StringWriter sw = new StringWriter(); JsonGenerator jgen = new JsonFactory(mapper()).createGenerator(sw); if (prettyPrint) { jgen.setPrettyPrinter(new DefaultPrettyPrinter()); } if (escapeNonASCII) { jgen.enable(Feature.ESCAPE_NON_ASCII); } mapper().writeValue(jgen, o); sw.flush(); return sw.toString(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Serialize parquet metadata to json and write to a file * @param parquetTableMetadata * @param p * @throws IOException */ private void writeFile(ParquetTableMetadata_v1 parquetTableMetadata, Path p) throws IOException { JsonFactory jsonFactory = new JsonFactory(); jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false); jsonFactory.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false); ObjectMapper mapper = new ObjectMapper(jsonFactory); FSDataOutputStream os = fs.create(p); mapper.writerWithDefaultPrettyPrinter().writeValue(os, parquetTableMetadata); os.flush(); os.close(); }
@Test public void testJson() throws Exception { JsonDataSource.Builder builder = JsonDataSource.builder(); builder.getFactory().enable(Feature.WRITE_NUMBERS_AS_STRINGS); DataSource dataSource = builder.setSink(sink).setSource(source).build(); fileSerializeComprehensive(dataSource); fileSerializeKComprehensive(dataSource); //fileSerializeCommonTypes(dataSource); }
private void enableDisableJSONGeneratorFeature(JsonGenerator jg) { jg.enable(Feature.ESCAPE_NON_ASCII); jg.disable(Feature.AUTO_CLOSE_TARGET); jg.setPrettyPrinter(new DefaultPrettyPrinter()); if (PDXTOJJSON_UNQUOTEFIELDNAMES) jg.disable(Feature.QUOTE_FIELD_NAMES); }
@Override public void serialize(OFFlowModMap fmm, JsonGenerator jGen, SerializerProvider serializer) throws IOException, JsonProcessingException { jGen.configure(Feature.WRITE_NUMBERS_AS_STRINGS, true); // IMHO this just looks nicer and is easier to read if everything is quoted if (fmm == null) { jGen.writeStartObject(); jGen.writeString("No flows have been added to the Static Flow Pusher."); jGen.writeEndObject(); return; } Map<String, Map<String, OFFlowMod>> theMap = fmm.getMap(); jGen.writeStartObject(); if (theMap.keySet() != null) { for (String dpid : theMap.keySet()) { if (theMap.get(dpid) != null) { jGen.writeArrayFieldStart(dpid); for (String name : theMap.get(dpid).keySet()) { jGen.writeStartObject(); jGen.writeFieldName(name); OFFlowModSerializer.serializeFlowMod(jGen, theMap.get(dpid).get(name)); jGen.writeEndObject(); } jGen.writeEndArray(); } } } jGen.writeEndObject(); }
@Override public void serialize(SwitchPortBandwidth spb, JsonGenerator jGen, SerializerProvider serializer) throws IOException, JsonProcessingException { jGen.configure(Feature.WRITE_NUMBERS_AS_STRINGS, true); jGen.writeStartObject(); jGen.writeStringField("dpid", spb.getSwitchId().toString()); jGen.writeStringField("port", spb.getSwitchPort().toString()); jGen.writeStringField("updated", new Date(spb.getUpdateTime()).toString()); jGen.writeStringField("bits-per-second-rx", spb.getBitsPerSecondRx().getBigInteger().toString()); jGen.writeStringField("bits-per-second-tx", spb.getBitsPerSecondTx().getBigInteger().toString()); jGen.writeEndObject(); }
/** * Serialize parquet metadata to json and write to a file * * @param parquetTableMetadata * @param p * @throws IOException */ private void writeFile(ParquetTableMetadata_v3 parquetTableMetadata, Path p) throws IOException { JsonFactory jsonFactory = new JsonFactory(); jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false); jsonFactory.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false); ObjectMapper mapper = new ObjectMapper(jsonFactory); SimpleModule module = new SimpleModule(); module.addSerializer(ColumnMetadata_v3.class, new ColumnMetadata_v3.Serializer()); mapper.registerModule(module); FSDataOutputStream os = fs.create(p); mapper.writerWithDefaultPrettyPrinter().writeValue(os, parquetTableMetadata); os.flush(); os.close(); }
private void writeFile(ParquetTableMetadataDirs parquetTableMetadataDirs, Path p) throws IOException { JsonFactory jsonFactory = new JsonFactory(); jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false); jsonFactory.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false); ObjectMapper mapper = new ObjectMapper(jsonFactory); SimpleModule module = new SimpleModule(); mapper.registerModule(module); FSDataOutputStream os = fs.create(p); mapper.writerWithDefaultPrettyPrinter().writeValue(os, parquetTableMetadataDirs); os.flush(); os.close(); }
protected ReactScriptEngine(ScriptEngineFactory scriptEngineFactory, ObjectPool<JavascriptEngine> enginePool, boolean reloadScripts, OsgiServiceFinder finder, DynamicClassLoaderManager dynamicClassLoaderManager) { super(scriptEngineFactory); this.mapper = new ObjectMapper(); mapper.configure(Feature.IGNORE_UNKNOWN, true); this.enginePool = enginePool; this.reloadScripts = reloadScripts; this.finder = finder; this.dynamicClassLoaderManager = dynamicClassLoaderManager; }
private JsonGenerator createJsonGenerator(OutputStream baos) throws IOException { JsonGenerator result = JSON_FACTORY.createGenerator(baos, UTF8); result.configure(Feature.QUOTE_NON_NUMERIC_NUMBERS, false); result.configure(Feature.AUTO_CLOSE_TARGET, false); if (this.logger.isDebugEnabled()) { result.setPrettyPrinter(new DefaultPrettyPrinter()); } return result; }
public GeneratorBase(int paramInt, ObjectCodec paramObjectCodec) { this._features = paramInt; this._writeContext = JsonWriteContext.createRootContext(); this._objectCodec = paramObjectCodec; this._cfgNumbersAsStrings = isEnabled(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS); }
public JsonGenerator disable(JsonGenerator.Feature paramFeature) { this._features &= (0xFFFFFFFF ^ paramFeature.getMask()); if (paramFeature == JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS) { this._cfgNumbersAsStrings = false; return this; } if (paramFeature == JsonGenerator.Feature.ESCAPE_NON_ASCII) setHighestNonEscapedChar(0); return this; }
public JsonGenerator enable(JsonGenerator.Feature paramFeature) { this._features |= paramFeature.getMask(); if (paramFeature == JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS) { this._cfgNumbersAsStrings = true; return this; } if (paramFeature == JsonGenerator.Feature.ESCAPE_NON_ASCII) setHighestNonEscapedChar(127); return this; }
protected final void _writeFieldName(String paramString, boolean paramBoolean) { if (this._cfgPrettyPrinter != null) { _writePPFieldName(paramString, paramBoolean); return; } if (1 + this._outputTail >= this._outputEnd) _flushBuffer(); if (paramBoolean) { char[] arrayOfChar3 = this._outputBuffer; int k = this._outputTail; this._outputTail = (k + 1); arrayOfChar3[k] = ','; } if (!isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES)) { _writeString(paramString); return; } char[] arrayOfChar1 = this._outputBuffer; int i = this._outputTail; this._outputTail = (i + 1); arrayOfChar1[i] = '"'; _writeString(paramString); if (this._outputTail >= this._outputEnd) _flushBuffer(); char[] arrayOfChar2 = this._outputBuffer; int j = this._outputTail; this._outputTail = (j + 1); arrayOfChar2[j] = '"'; }
public final void writeNumber(double paramDouble) { if ((this._cfgNumbersAsStrings) || (((Double.isNaN(paramDouble)) || (Double.isInfinite(paramDouble))) && (isEnabled(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS)))) { writeString(String.valueOf(paramDouble)); return; } _verifyValueWrite("write number"); writeRaw(String.valueOf(paramDouble)); }
public final void writeNumber(float paramFloat) { if ((this._cfgNumbersAsStrings) || (((Float.isNaN(paramFloat)) || (Float.isInfinite(paramFloat))) && (isEnabled(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS)))) { writeString(String.valueOf(paramFloat)); return; } _verifyValueWrite("write number"); writeRaw(String.valueOf(paramFloat)); }
public JsonGeneratorImpl(IOContext paramIOContext, int paramInt, ObjectCodec paramObjectCodec) { super(paramInt, paramObjectCodec); this._ioContext = paramIOContext; if (isEnabled(JsonGenerator.Feature.ESCAPE_NON_ASCII)) setHighestNonEscapedChar(127); }
public UTF8JsonGenerator(IOContext paramIOContext, int paramInt, ObjectCodec paramObjectCodec, OutputStream paramOutputStream) { super(paramIOContext, paramInt, paramObjectCodec); this._outputStream = paramOutputStream; this._bufferRecyclable = true; this._outputBuffer = paramIOContext.allocWriteEncodingBuffer(); this._outputEnd = this._outputBuffer.length; this._outputMaxContiguous = (this._outputEnd >> 3); this._charBuffer = paramIOContext.allocConcatBuffer(); this._charBufferLength = this._charBuffer.length; if (isEnabled(JsonGenerator.Feature.ESCAPE_NON_ASCII)) setHighestNonEscapedChar(127); }