ImmutablePayload implements Payload { public static ImmutablePayload fromJson(final JsonObject jsonObject) { final String readPath = jsonObject.getValueOrThrow(JsonFields.PATH); final ImmutablePayloadBuilder payloadBuilder = getBuilder(JsonFactory.newPointer(readPath)) .withValue(jsonObject.getValue(JsonFields.VALUE).orElse(null)) .withExtra(jsonObject.getValue(JsonFields.EXTRA).orElse(null)) .withStatus(jsonObject.getValue(JsonFields.STATUS).flatMap(HttpStatusCode::forInt).orElse(null)) .withTimestamp(jsonObject.getValue(JsonFields.TIMESTAMP).map(Instant::parse).orElse(null)) .withMetadata(jsonObject.getValue(JsonFields.METADATA).map(Metadata::newMetadata).orElse(null)) .withFields(jsonObject.getValue(JsonFields.FIELDS) .map(JsonFactory::parseJsonFieldSelector) .orElse(null)); jsonObject.getValue(JsonFields.REVISION).ifPresent(payloadBuilder::withRevision); return payloadBuilder.build(); } private  ImmutablePayload(final ImmutablePayloadBuilder builder); static ImmutablePayloadBuilder getBuilder(@Nullable final JsonPointer path); static ImmutablePayload fromJson(final JsonObject jsonObject); @Override MessagePath getPath(); @Override Optional<JsonValue> getValue(); @Override Optional<JsonObject> getExtra(); @Override Optional<HttpStatusCode> getStatus(); @Override Optional<Long> getRevision(); @Override Optional<Instant> getTimestamp(); @Override Optional<Metadata> getMetadata(); @Override Optional<JsonFieldSelector> getFields(); @Override JsonObject toJson(); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void fromJsonWorksAsExpected() { assertThat(ImmutablePayload.fromJson(knownJsonRepresentation)).isEqualTo(knownPayload); }