/** * Deserialize credentials from JSON. * * @param jsonObject credentials in JSON format. * @return deserialized credentials. */ static Credentials fromJson(final JsonObject jsonObject) { final String type = jsonObject.getValueOrThrow(JsonFields.TYPE); final Function<JsonObject, Credentials> deserializer = JsonFields.DESERIALIZER_MAP.get(type); if (deserializer == null) { throw JsonParseException.newBuilder() .message(String.format("Unknown credential type <%s>", type)) .description("Original JSON: " + jsonObject.toString()) .build(); } return deserializer.apply(jsonObject); }
/** * Deserialize credentials from JSON. * * @param jsonObject credentials in JSON format. * @return deserialized credentials. */ static Credentials fromJson(final JsonObject jsonObject) { final String type = jsonObject.getValueOrThrow(JsonFields.TYPE); final Function<JsonObject, Credentials> deserializer = JsonFields.DESERIALIZER_MAP.get(type); if (deserializer == null) { throw JsonParseException.newBuilder() .message(String.format("Unknown credential type <%s>", type)) .description("Original JSON: " + jsonObject.toString()) .build(); } return deserializer.apply(jsonObject); }
/** * Creates a new {@code SudoRetrieveModifiedThingTags} from a JSON object. * * @param jsonObject the JSON object of which a new SudoRetrieveModifiedThingTags is to be created. * @param dittoHeaders the optional command headers of the request. * @return the SudoRetrieveModifiedThingTags which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws JsonMissingFieldException if the passed in {@code jsonObject} was not in the expected format. */ public static SudoStreamModifiedEntities fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { try { final Instant start = Instant.parse(jsonObject.getValueOrThrow(JSON_START)); final Instant end = Instant.parse(jsonObject.getValueOrThrow(JSON_END)); final Integer burst = jsonObject.getValue(JSON_BURST).orElse(null); final Long timeoutMillis = jsonObject.getValue(JSON_TIMEOUT_MILLIS).orElse(null); return SudoStreamModifiedEntities.of(start, end, burst, timeoutMillis, dittoHeaders); } catch (final DateTimeParseException e) { throw JsonParseException.newBuilder() .message("A given instant is not a valid timestamp.") .description(jsonObject.toString()) .cause(e) .build(); } }