@Override public WithEntity setEntity(final JsonValue entity) { final ConnectionStatus connectionStatusToSet = ConnectionStatus.forName(entity.asString()).orElse(ConnectionStatus.UNKNOWN); return of(connectionId, connectionStatusToSet, getDittoHeaders()); }
@Override public WithEntity setEntity(final JsonValue entity) { final ConnectionStatus connectionStatusToSet = ConnectionStatus.forName(entity.asString()).orElse(ConnectionStatus.UNKNOWN); return of(connectionId, connectionStatusToSet, getDittoHeaders()); }
private static ConnectionStatus getConnectionStatusOrThrow(final JsonObject jsonObject) { final String readConnectionStatus = jsonObject.getValueOrThrow(JsonFields.CONNECTION_STATUS); return ConnectionStatus.forName(readConnectionStatus) .orElseThrow(() -> JsonParseException.newBuilder() .message(MessageFormat.format("Connection status <{0}> is invalid!", readConnectionStatus)) .build()); }
private static ConnectionStatus getConnectionStatusOrThrow(final JsonObject jsonObject) { final String readConnectionStatus = jsonObject.getValueOrThrow(JsonFields.CONNECTION_STATUS); return ConnectionStatus.forName(readConnectionStatus) .orElseThrow(() -> JsonParseException.newBuilder() .message(MessageFormat.format("Connection status <{0}> is invalid!", readConnectionStatus)) .build()); }
/** * Creates a new {@code AddressMetric} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the AddressMetric to be created. * @return a new AddressMetric which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static AddressMetric fromJson(final JsonObject jsonObject) { final ConnectionStatus readConnectionStatus = ConnectionStatus.forName( jsonObject.getValueOrThrow(JsonFields.STATUS)).orElse(ConnectionStatus.UNKNOWN); final String readConnectionStatusDetails = jsonObject.getValue(JsonFields.STATUS_DETAILS) .orElse(null); final long readConsumedMessages = jsonObject.getValueOrThrow(JsonFields.MESSAGE_COUNT); final Instant readLastMessageAt = jsonObject.getValue(JsonFields.LAST_MESSAGE_AT).map(Instant::parse) .orElse(null); return ImmutableAddressMetric.of(readConnectionStatus, readConnectionStatusDetails, readConsumedMessages, readLastMessageAt); }
/** * Creates a new {@code AddressMetric} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the AddressMetric to be created. * @return a new AddressMetric which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static AddressMetric fromJson(final JsonObject jsonObject) { final ConnectionStatus readConnectionStatus = ConnectionStatus.forName( jsonObject.getValueOrThrow(JsonFields.STATUS)).orElse(ConnectionStatus.UNKNOWN); final String readConnectionStatusDetails = jsonObject.getValue(JsonFields.STATUS_DETAILS) .orElse(null); final long readConsumedMessages = jsonObject.getValueOrThrow(JsonFields.MESSAGE_COUNT); final Instant readLastMessageAt = jsonObject.getValue(JsonFields.LAST_MESSAGE_AT).map(Instant::parse) .orElse(null); return ImmutableAddressMetric.of(readConnectionStatus, readConnectionStatusDetails, readConsumedMessages, readLastMessageAt); }
final ConnectionStatus readConnectionStatus = ConnectionStatus.forName( jsonObject.getValueOrThrow(JsonFields.CONNECTION_STATUS)).orElse(ConnectionStatus.UNKNOWN); final String readConnectionStatusDetails = jsonObject.getValue(JsonFields.CONNECTION_STATUS_DETAILS)
final ConnectionStatus readConnectionStatus = ConnectionStatus.forName( jsonObject.getValueOrThrow(JsonFields.CONNECTION_STATUS)).orElse(ConnectionStatus.UNKNOWN); final String readConnectionStatusDetails = jsonObject.getValue(JsonFields.CONNECTION_STATUS_DETAILS)
/** * Creates a new {@code RetrieveConnectionStatusResponse} from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the response. * @return the response. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static RetrieveConnectionStatusResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<RetrieveConnectionStatusResponse>(TYPE, jsonObject).deserialize( statusCode -> { final String readConnectionId = jsonObject.getValueOrThrow(ConnectivityCommandResponse.JsonFields.JSON_CONNECTION_ID); final ConnectionStatus readConnectionStatus = ConnectionStatus.forName(jsonObject.getValueOrThrow(JSON_CONNECTION_STATUS)) .orElse(ConnectionStatus.UNKNOWN); return of(readConnectionId, readConnectionStatus, dittoHeaders); }); }
/** * Creates a new {@code RetrieveConnectionStatusResponse} from a JSON object. * * @param jsonObject the JSON object of which the response is to be created. * @param dittoHeaders the headers of the response. * @return the response. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static RetrieveConnectionStatusResponse fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new CommandResponseJsonDeserializer<RetrieveConnectionStatusResponse>(TYPE, jsonObject).deserialize( statusCode -> { final String readConnectionId = jsonObject.getValueOrThrow(ConnectivityCommandResponse.JsonFields.JSON_CONNECTION_ID); final ConnectionStatus readConnectionStatus = ConnectionStatus.forName(jsonObject.getValueOrThrow(JSON_CONNECTION_STATUS)) .orElse(ConnectionStatus.UNKNOWN); return of(readConnectionId, readConnectionStatus, dittoHeaders); }); }