public MalformedJsonException(String msg, Throwable throwable) { super(msg); // Using initCause() instead of calling super() because Java 1.5 didn't retrofit IOException // with a constructor with Throwable. This was done in Java 1.6 initCause(throwable); }
private JsonWriter(Writer writer) { this.stream = new com.google.gson.stream.JsonWriter(writer); this.stream.setSerializeNulls(false); this.stream.setLenient(false); this.serializeEmptyStrings = true; }
public JsonWriter setSerializeNulls(boolean b) { this.stream.setSerializeNulls(b); return this; }
@NotNull private static JsonWriter writeScope(int frameId, @NotNull JsonWriter writer) throws IOException { // todo: ask vladimir how to simplify this return writer.beginObject() .name("Scope").beginObject() .name("GoroutineID").value(-1) .name("Frame").value(frameId).endObject(); }
public static void writeNullSafeArray(JsonWriter writer, Set<String> items) throws IOException { if (items != null) { writer.beginArray(); for (String s : items) { writer.value(s); } writer.endArray(); } else { writer.nullValue(); } }
@Override protected void writeCustomized(final JsonWriter out, final LiteJobConfiguration value) throws IOException { out.name(MONITOR_EXECUTION).value(value.isMonitorExecution()); out.name(MAX_TIME_DIFF_SECONDS).value(value.getMaxTimeDiffSeconds()); out.name(MONITOR_PORT).value(value.getMonitorPort()); out.name(JOB_SHARDING_STRATEGY_CLASS).value(value.getJobShardingStrategyClass()); out.name(RECONCILE_INTERVAL_MINUTES).value(value.getReconcileIntervalMinutes()); out.name(DISABLED).value(value.isDisabled()); out.name(OVERWRITE).value(value.isOverwrite()); } }
@Override public T convert(ResponseBody value) throws IOException { JsonReader jsonReader = gson.newJsonReader(value.charStream()); try { T result = adapter.read(jsonReader); if (jsonReader.peek() != JsonToken.END_DOCUMENT) { throw new JsonIOException("JSON document was not fully consumed."); } return result; } finally { value.close(); } } }
/** * Ends encoding the current object. Output is <code>}</code>. * * @throws org.sonar.api.utils.text.WriterException on any failure */ public JsonWriter endObject() { try { stream.endObject(); return this; } catch (Exception e) { throw rethrow(e); } }
void setWriterOptions(JsonWriter writer) { writer.setSerializeNulls(serializeNulls); writer.setLenient(lenient); writer.setHtmlSafe(htmlSafe); writer.setIndent(prettyPrinting ? " " : ""); } }
/** * Ends encoding the current array. Output is <code>]</code>. * * @throws org.sonar.api.utils.text.WriterException on any failure */ public JsonWriter endArray() { try { stream.endArray(); return this; } catch (Exception e) { throw rethrow(e); } }
/** * @throws org.sonar.api.utils.text.WriterException on any failure */ @Override public void close() { try { stream.close(); } catch (Exception e) { throw rethrow(e); } }
void setReaderOptions(JsonReader reader) { reader.setLenient(lenient); }
/** * @throws org.sonar.api.utils.text.WriterException on any failure */ public JsonWriter value(double value) { try { stream.value(value); return this; } catch (Exception e) { throw rethrow(e); } }
@Override public RequestBody convert(T value) throws IOException { Buffer buffer = new Buffer(); Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8); JsonWriter jsonWriter = gson.newJsonWriter(writer); adapter.write(jsonWriter, value); jsonWriter.close(); return RequestBody.create(MEDIA_TYPE, buffer.readByteString()); } }
public MalformedJsonException(Throwable throwable) { // Using initCause() instead of calling super() because Java 1.5 didn't retrofit IOException // with a constructor with Throwable. This was done in Java 1.6 initCause(throwable); } }
/** * @throws org.sonar.api.utils.text.WriterException on any failure */ public JsonWriter value(long value) { try { stream.value(value); return this; } catch (Exception e) { throw rethrow(e); } }
/** * Encodes {@code value}. Output is <code>true</code> or <code>false</code>. * * @throws org.sonar.api.utils.text.WriterException on any failure */ public JsonWriter value(boolean value) { try { stream.value(value); return this; } catch (Exception e) { throw rethrow(e); } }