@Override public String toString() { StringWriter stringWriter = new StringWriter(); try (JsonWriter jsonWriter = new JsonWriter(stringWriter)) { jsonWriter.setIndent("\t"); this.toJson(jsonWriter, false); } catch (IOException ioe) { // Ignored } return stringWriter.toString(); }
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public void exportData(HttpServletResponse resp, Principal prin) throws IOException { resp.setContentType(MediaType.APPLICATION_JSON_VALUE); // this writer puts things out onto the wire JsonWriter writer = new JsonWriter(resp.getWriter()); writer.setIndent(" "); try { writer.beginObject(); writer.name("exported-at"); writer.value(dateFormat.format(new Date())); writer.name("exported-from"); writer.value(config.getIssuer()); writer.name("exported-by"); writer.value(prin.getName()); // delegate to the service to do the actual export exporter.exportData(writer); writer.endObject(); // end root writer.close(); } catch (IOException e) { logger.error("Unable to export data", e); } }
/** * Convert all past {@link JobState}s of the given job. * * @param jobName job name * @param writer {@link java.io.Writer} to write the json document * @throws IOException */ public void convertAll(String jobName, Writer writer) throws IOException { List<? extends JobState> jobStates = this.jobStateStore.getAll(jobName); if (jobStates.isEmpty()) { LOGGER.warn(String.format("No job state found for job with name %s", jobName)); return; } try (JsonWriter jsonWriter = new JsonWriter(writer)) { jsonWriter.setIndent("\t"); writeJobStates(jsonWriter, jobStates); } }
/** * Convert a single {@link JobState} of the given job instance. * * @param jobName job name * @param jobId job ID * @param writer {@link java.io.Writer} to write the json document * @throws IOException */ public void convert(String jobName, String jobId, Writer writer) throws IOException { List<? extends JobState> jobStates = this.jobStateStore.getAll(jobName, jobId + JOB_STATE_STORE_TABLE_SUFFIX); if (jobStates.isEmpty()) { LOGGER.warn(String.format("No job state found for job with name %s and id %s", jobName, jobId)); return; } try (JsonWriter jsonWriter = new JsonWriter(writer)) { jsonWriter.setIndent("\t"); // There should be only a single job state writeJobState(jsonWriter, jobStates.get(0)); } }
void setWriterOptions(JsonWriter writer) { writer.setSerializeNulls(serializeNulls); writer.setLenient(lenient); writer.setHtmlSafe(htmlSafe); writer.setIndent(prettyPrinting ? " " : ""); } }
void readZooKeeper(OutputStream zkData, AuthMode authMode, byte[] authData) throws IOException, KeeperException, InterruptedException, ExecutionException { ZooKeeper zooKeeper = getZooKeeper(zooKeeperEndpointConfig.getConnectString(), authMode, authData); JsonWriter jsonWriter = new JsonWriter(new BufferedWriter(new OutputStreamWriter(zkData))); jsonWriter.setIndent(" "); JsonParser jsonParser = new JsonParser(); Gson gson = new GsonBuilder().create();
writer.setIndent(" "); while (true) { final JsonToken token = reader.peek();
@Override public void setIndent(String indent) { gson.setIndent(indent); }
@Override public void setIndent(String indent) { gson.setIndent(indent); }
@Override public void setIndent(String indent) { if (!indent.equals("")) throw new Error("do not use pretty when canonical is set"); gson.setIndent(indent); }
/** * Returns a new JSON writer configured for the settings on this Gson instance. */ public JsonWriter newJsonWriter(Writer writer) throws IOException { if (generateNonExecutableJson) { writer.write(JSON_NON_EXECUTABLE_PREFIX); } JsonWriter jsonWriter = new JsonWriter(writer); if (prettyPrinting) { jsonWriter.setIndent(" "); } jsonWriter.setSerializeNulls(serializeNulls); return jsonWriter; }
public static String toJson(DynamoDBEntry entry, boolean prettyPrint) throws IOException { final StringWriter jsonString = new StringWriter(); final JsonWriter writer = new JsonWriter(jsonString); if (prettyPrint) { writer.setIndent(" "); } writeJson(entry, writer); writer.close(); return jsonString.toString(); }
/** * Serialize bulk load mapping to {@value Constants#BULK_LOAD_MAPPING} */ public static void writeLoadMapping(SortedMap<KeyExtent,Bulk.Files> loadMapping, String sourceDir, Output output) throws IOException { final Path lmFile = new Path(sourceDir, Constants.BULK_LOAD_MAPPING); try (OutputStream fsOut = output.create(lmFile); JsonWriter writer = new JsonWriter( new BufferedWriter(new OutputStreamWriter(fsOut, UTF_8)))) { Gson gson = createGson(); writer.setIndent(" "); writer.beginArray(); Set<Entry<KeyExtent,Files>> es = loadMapping.entrySet(); for (Entry<KeyExtent,Files> entry : es) { Mapping mapping = new Bulk.Mapping(entry.getKey(), entry.getValue()); gson.toJson(mapping, Mapping.class, writer); } writer.endArray(); } }
@Override public JsonLikeWriter init() throws IOException { eventWriter = new JsonWriter(getWriter()); eventWriter.setSerializeNulls(true); if (isPrettyPrint()) { eventWriter.setIndent(" "); } blockType = BlockType.NONE; blockStack.clear(); return this; }
@Override public void startSerialization() throws IOException { writer.beginObject(); writer.setIndent("\t"); }
public BdioWriter(final Gson gson, final OutputStream outputStream) throws IOException { this.gson = gson; jsonWriter = new JsonWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)); jsonWriter.setIndent(" "); jsonWriter.beginArray(); }
@Override public String toString() { StringWriter stringWriter = new StringWriter(); try (JsonWriter jsonWriter = new JsonWriter(stringWriter)) { jsonWriter.setIndent("\t"); this.toJson(jsonWriter, false); } catch (IOException ioe) { // Ignored } return stringWriter.toString(); }
private JsonWriter makePrettyJsonWriter(Appendable appendable) { JsonWriter jsonWriter = new JsonWriter(Streams.writerForAppendable(appendable)); jsonWriter.setIndent(JSON_INDENT); return jsonWriter; }
@Override public JsonLikeWriter init() throws IOException { eventWriter = new JsonWriter(getWriter()); eventWriter.setSerializeNulls(true); if (isPrettyPrint()) { eventWriter.setIndent(" "); } blockType = BlockType.NONE; blockStack.clear(); return this; }
void setWriterOptions(JsonWriter writer) { writer.setSerializeNulls(serializeNulls); writer.setLenient(lenient); writer.setHtmlSafe(htmlSafe); writer.setIndent(prettyPrinting ? " " : ""); } }