class ImmutableMeasurement implements Measurement {

    @Override
    public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) {
        final JsonObject counts = values.entrySet()
                .stream()
                .sorted(Comparator.comparing(Map.Entry::getKey))
                .map(e -> JsonFactory.newField(JsonFactory.newKey(e.getKey().toString()), JsonValue.of(e.getValue())))
                .collect(JsonCollectors.fieldsToObject());

        return JsonFactory.newObjectBuilder()
                .set(metricType.getName(),
                        JsonFactory.newObjectBuilder()
                                .set(getSuccessFieldName(success),
                                        JsonFactory.newObjectBuilder(counts)
                                                .set(JsonFields.LAST_MESSAGE_AT, getLastMessageAt()
                                                        .map(Object::toString).orElse(null)
                                                ).build()
                                ).build()
                ).build();
    }

      ImmutableMeasurement(final MetricType metricType, final boolean success,
            final Map<Duration, Long> values, @Nullable final Instant lastMessageAt);

}