@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; } }
@FromJson @Nullable Stage fromJson(JsonReader jsonReader, JsonAdapter<Stage> delegate) throws IOException { String value = jsonReader.nextString(); Stage stage; if (value.startsWith("in-progress")) { stage = Stage.IN_PROGRESS; } else { stage = delegate.fromJsonValue(value); } return stage; } }
@Override public T fromJson(JsonReader reader) throws IOException { Object jsonValue = reader.readJsonValue(); try { return delegate.fromJsonValue(jsonValue); } catch (JsonDataException ignore) { return defaultValue; } }