@Override public T fromJson(JsonReader reader) throws IOException { // Read the value first so that the reader will be in a known state even if there's an // exception. Otherwise it may be awkward to recover: it might be between calls to // beginObject() and endObject() for example. Object jsonValue = reader.readJsonValue(); // Use the delegate to convert the JSON value to the target type. try { return delegate.fromJsonValue(jsonValue); } catch (JsonDataException e) { return defaultValue; } }
@Override public JsonWriter value(BufferedSource source) throws IOException { if (promoteValueToName) { throw new IllegalStateException( "BufferedSource cannot be used as a map key in JSON at path " + getPath()); } Object value = JsonReader.of(source).readJsonValue(); boolean serializeNulls = this.serializeNulls; this.serializeNulls = true; try { add(value); } finally { this.serializeNulls = serializeNulls; } pathIndices[stackSize - 1]++; return this; }
beginArray(); while (hasNext()) { list.add(readJsonValue()); while (hasNext()) { String name = nextName(); Object value = readJsonValue(); Object replaced = map.put(name, value); if (replaced != null) {
@Override public T fromJson(JsonReader reader) throws IOException { Object jsonValue = reader.readJsonValue(); try { return delegate.fromJsonValue(jsonValue); } catch (JsonDataException ignore) { return defaultValue; } }
@Override String format(String source) { Buffer buffer = new Buffer().writeUtf8(source); JsonReader reader = JsonReader.of(buffer); try { return ADAPTER.toJson(reader.readJsonValue()); } catch (IOException e) { return ""; } }
@Override public JsonWriter value(BufferedSource source) throws IOException { if (promoteValueToName) { throw new IllegalStateException( "BufferedSource cannot be used as a map key in JSON at path " + getPath()); } Object value = JsonReader.of(source).readJsonValue(); boolean serializeNulls = this.serializeNulls; this.serializeNulls = true; try { add(value); } finally { this.serializeNulls = serializeNulls; } pathIndices[stackSize - 1]++; return this; }
beginArray(); while (hasNext()) { list.add(readJsonValue()); while (hasNext()) { String name = nextName(); Object value = readJsonValue(); Object replaced = map.put(name, value); if (replaced != null) {