ImmutableTarget implements Target { public static Target fromJson(final JsonObject jsonObject) { final Set<FilteredTopic> readTopics = jsonObject.getValue(JsonFields.TOPICS) .map(array -> array.stream() .map(JsonValue::asString) .map(ConnectivityModelFactory::newFilteredTopic) .collect(Collectors.toSet())) .orElse(Collections.emptySet()); final JsonArray authContext = jsonObject.getValue(JsonFields.AUTHORIZATION_CONTEXT) .orElseGet(() -> JsonArray.newBuilder().build()); final List<AuthorizationSubject> authorizationSubjects = authContext.stream() .filter(JsonValue::isString) .map(JsonValue::asString) .map(AuthorizationSubject::newInstance) .collect(Collectors.toList()); final AuthorizationContext readAuthorizationContext = AuthorizationModelFactory.newAuthContext(DittoAuthorizationContextType.PRE_AUTHENTICATED_CONNECTION, authorizationSubjects); final AcknowledgementLabel readIssuedAcknowledgementLabel = jsonObject.getValue(Target.JsonFields.ISSUED_ACKNOWLEDGEMENT_LABEL) .map(AcknowledgementLabel::of) .orElse(null); final HeaderMapping readHeaderMapping = jsonObject.getValue(JsonFields.HEADER_MAPPING) .map(ImmutableHeaderMapping::fromJson) .orElse(null); final PayloadMapping readMapping = jsonObject.getValue(JsonFields.PAYLOAD_MAPPING) .map(ImmutablePayloadMapping::fromJson) .orElse(ConnectivityModelFactory.emptyPayloadMapping()); return new Builder() .address(jsonObject.getValueOrThrow(JsonFields.ADDRESS)) .topics(readTopics) .qos(jsonObject.getValue(JsonFields.QOS).orElse(null)) .authorizationContext(readAuthorizationContext) .issuedAcknowledgementLabel(readIssuedAcknowledgementLabel) .headerMapping(readHeaderMapping) .payloadMapping(readMapping) .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 fromJsonReturnsExpected() { final Target actual = ImmutableTarget.fromJson(TARGET_JSON_WITH_AUTH_CONTEXT); assertThat(actual).isEqualTo(TARGET_WITH_AUTH_CONTEXT); }
@Test public void mqttFromJsonReturnsExpected() { final Target actual = ImmutableTarget.fromJson(MQTT_TARGET_JSON); assertThat(actual).isEqualTo(MQTT_TARGET); }