/** Before pushing a value on the stack this confirms that the stack has capacity. */ final boolean checkStack() { if (stackSize != scopes.length) return false; if (stackSize == 256) { throw new JsonDataException("Nesting too deep at " + getPath() + ": circular reference?"); } scopes = Arrays.copyOf(scopes, scopes.length * 2); pathNames = Arrays.copyOf(pathNames, pathNames.length * 2); pathIndices = Arrays.copyOf(pathIndices, pathIndices.length * 2); if (this instanceof JsonValueWriter) { ((JsonValueWriter) this).stack = Arrays.copyOf(((JsonValueWriter) this).stack, ((JsonValueWriter) this).stack.length * 2); } return true; }
@Override public void toJson(JsonWriter writer, @Nullable T value) throws IOException { if (value == null) { throw new JsonDataException("Unexpected null at " + writer.getPath()); } else { delegate.toJson(writer, value); } } @Override boolean isLenient() {
@Override public void toJson(JsonWriter writer, Map<K, V> map) throws IOException { writer.beginObject(); for (Map.Entry<K, V> entry : map.entrySet()) { if (entry.getKey() == null) { throw new JsonDataException("Map key is null at " + writer.getPath()); } writer.promoteValueToName(); keyAdapter.toJson(writer, entry.getKey()); valueAdapter.toJson(writer, entry.getValue()); } writer.endObject(); }
@Override public void toJson(JsonWriter writer, @Nullable Object value) throws IOException { if (toAdapter == null) { delegate.toJson(writer, value); } else if (!toAdapter.nullable && value == null) { writer.nullValue(); } else { try { toAdapter.toJson(moshi, writer, value); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) throw (IOException) cause; throw new JsonDataException(cause + " at " + writer.getPath(), cause); } } }
/** Before pushing a value on the stack this confirms that the stack has capacity. */ final boolean checkStack() { if (stackSize != scopes.length) return false; if (stackSize == 256) { throw new JsonDataException("Nesting too deep at " + getPath() + ": circular reference?"); } scopes = Arrays.copyOf(scopes, scopes.length * 2); pathNames = Arrays.copyOf(pathNames, pathNames.length * 2); pathIndices = Arrays.copyOf(pathIndices, pathIndices.length * 2); if (this instanceof JsonValueWriter) { ((JsonValueWriter) this).stack = Arrays.copyOf(((JsonValueWriter) this).stack, ((JsonValueWriter) this).stack.length * 2); } return true; }
@Override public void toJson(JsonWriter writer, @Nullable T value) throws IOException { if (value == null) { throw new JsonDataException("Unexpected null at " + writer.getPath()); } else { delegate.toJson(writer, value); } } @Override boolean isLenient() {
@Override public void toJson(JsonWriter writer, Map<K, V> map) throws IOException { writer.beginObject(); for (Map.Entry<K, V> entry : map.entrySet()) { if (entry.getKey() == null) { throw new JsonDataException("Map key is null at " + writer.getPath()); } writer.promoteValueToName(); keyAdapter.toJson(writer, entry.getKey()); valueAdapter.toJson(writer, entry.getValue()); } writer.endObject(); }
@Override public void toJson(JsonWriter writer, @Nullable Object value) throws IOException { if (toAdapter == null) { delegate.toJson(writer, value); } else if (!toAdapter.nullable && value == null) { writer.nullValue(); } else { try { toAdapter.toJson(moshi, writer, value); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) throw (IOException) cause; throw new JsonDataException(cause + " at " + writer.getPath(), cause); } } }