ImmutableTarget implements Target { @Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder(); jsonObjectBuilder.set(JsonFields.SCHEMA_VERSION, schemaVersion.toInt(), predicate); jsonObjectBuilder.set(JsonFields.ADDRESS, address, predicate); jsonObjectBuilder.set(JsonFields.TOPICS, topics.stream() .map(FilteredTopic::toString) .map(JsonFactory::newValue) .collect(JsonCollectors.valuesToArray()), predicate.and(Objects::nonNull)); if (qos != null) { jsonObjectBuilder.set(JsonFields.QOS, qos, predicate); } if (!authorizationContext.isEmpty()) { jsonObjectBuilder.set(JsonFields.AUTHORIZATION_CONTEXT, authorizationContext.stream() .map(AuthorizationSubject::getId) .map(JsonFactory::newValue) .collect(JsonCollectors.valuesToArray()), predicate); } if (issuedAcknowledgementLabel != null) { jsonObjectBuilder.set(JsonFields.ISSUED_ACKNOWLEDGEMENT_LABEL, issuedAcknowledgementLabel.toString(), predicate); } if (headerMapping != null) { jsonObjectBuilder.set(JsonFields.HEADER_MAPPING, headerMapping.toJson(schemaVersion, thePredicate), predicate); } if (!payloadMapping.isEmpty()) { jsonObjectBuilder.set(Target.JsonFields.PAYLOAD_MAPPING, payloadMapping.toJson(), predicate); } return jsonObjectBuilder.build(); } private  ImmutableTarget(final ImmutableTarget.Builder builder); @Override String getAddress(); @Override String getOriginalAddress(); @Override Target withAddress(final String newAddress); @Override Set<FilteredTopic> getTopics(); @Override Optional<Integer> getQos(); @Override AuthorizationContext getAuthorizationContext(); @Override Optional<AcknowledgementLabel> getIssuedAcknowledgementLabel(); @Override Optional<HeaderMapping> getHeaderMapping(); @Override PayloadMapping getPayloadMapping(); @Override JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate); static Target fromJson(final JsonObject jsonObject); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void toJsonReturnsExpected() { final JsonObject actual = TARGET_WITH_AUTH_CONTEXT.toJson(); assertThat(actual).isEqualTo(TARGET_JSON_WITH_AUTH_CONTEXT); }
@Test public void mqttToJsonReturnsExpected() { final JsonObject actual = MQTT_TARGET.toJson(); assertThat(actual).isEqualTo(MQTT_TARGET_JSON); }