ImmutablePayload implements Payload { @Override public JsonObject toJson() { final JsonObjectBuilder jsonObjectBuilder = JsonObject.newBuilder(); jsonObjectBuilder.set(JsonFields.PATH, path.toString()); if (null != value) { jsonObjectBuilder.set(JsonFields.VALUE, value); } if (null != extra) { jsonObjectBuilder.set(JsonFields.EXTRA, extra); } if (null != status) { jsonObjectBuilder.set(JsonFields.STATUS, status.toInt()); } if (null != revision) { jsonObjectBuilder.set(JsonFields.REVISION, revision); } if (null != timestamp) { jsonObjectBuilder.set(JsonFields.TIMESTAMP, timestamp.toString()); } if (null != metadata) { jsonObjectBuilder.set(JsonFields.METADATA, metadata.toJson()); } if (null != fields) { jsonObjectBuilder.set(JsonFields.FIELDS, fields.toString()); } return jsonObjectBuilder.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 toJsonWorksAsExpected() { assertThat(knownPayload.toJson()).isEqualTo(knownJsonRepresentation); }