ImmutableAddressMetric implements AddressMetric { public static AddressMetric fromJson(final JsonObject jsonObject) { final Set<Measurement> readMeasurements = new HashSet<>(); jsonObject.stream() .filter(field -> field.getValue().isObject()) .forEach(f -> Stream.of(SUCCESS_KEY, FAILURE_KEY) .map(key -> JsonFactory.newPointer(JsonFactory.newKey(f.getKeyName()), key)) .map(jsonObject::get) .filter(JsonValue::isObject) .filter(o -> !o.isEmpty()) .map(JsonValue::asObject) .map(ImmutableMeasurement::fromJson) .forEach(readMeasurements::add)); return ImmutableAddressMetric.of(readMeasurements); } private  ImmutableAddressMetric(final Set<Measurement> measurements); static ImmutableAddressMetric of(final Set<Measurement> measurements); @Override Set<Measurement> getMeasurements(); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate); static AddressMetric fromJson(final JsonObject jsonObject); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void fromJsonReturnsExpected() { final AddressMetric actual = ImmutableAddressMetric.fromJson(METRIC_JSON); assertThat(actual).isEqualTo(ADDRESS_METRIC); }