/** * Parses an instance of {@link T} from the given {@code jsonString} and {@code dittoHeaders}. * * @param jsonString the JSON String representation to be parsed. * @param dittoHeaders the headers of the command to be parsed. * @return the parsed instance of {@link T} * @throws NullPointerException if {@code jsonString} is {@code null}. * @throws IllegalArgumentException if {@code jsonString} is empty. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonString} does not contain a valid JSON object. * @throws JsonTypeNotParsableException if the {@code jsonObject}'s {@code type} was unknown to the parser. */ default T parse(final String jsonString, final DittoHeaders dittoHeaders) { return parse(JsonFactory.newObject(jsonString), dittoHeaders); }
/** * Parses an instance of {@link T} from the given {@code jsonString} and {@code dittoHeaders}. * * @param jsonString the JSON String representation to be parsed. * @param dittoHeaders the headers of the command to be parsed. * @return the parsed instance of {@link T} * @throws NullPointerException if {@code jsonString} is {@code null}. * @throws IllegalArgumentException if {@code jsonString} is empty. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonString} does not contain a valid JSON object. * @throws JsonTypeNotParsableException if the {@code jsonObject}'s {@code type} was unknown to the parser. */ default T parse(final String jsonString, final DittoHeaders dittoHeaders) { return parse(JsonFactory.newObject(jsonString), dittoHeaders); }
private T fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { final String type = resolveType(jsonObject); final JsonParsable<T> jsonObjectParsable = parseStrategies.get(type); if (null != jsonObjectParsable) { try { return jsonObjectParsable.parse(jsonObject, dittoHeaders); } catch (final JsonRuntimeException jre) { final JsonExceptionBuilder builder = JsonRuntimeException.newBuilder(jre.getErrorCode()) .message("Error when parsing Json type '" + type + "': " + jre.getMessage()) .cause(jre.getCause()); jre.getDescription().ifPresent(builder::description); jre.getHref().ifPresent(builder::href); // rethrow after enhancing the exception with the type which failed to parse throw (JsonRuntimeException) builder.build(); } } else { throw JsonTypeNotParsableException.newBuilder(type, getClass().getSimpleName()) .dittoHeaders(dittoHeaders) .build(); } }
private T fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { final String type = resolveType(jsonObject); final JsonParsable<T> jsonObjectParsable = parseStrategies.get(type); if (null != jsonObjectParsable) { try { return jsonObjectParsable.parse(jsonObject, dittoHeaders); } catch (final JsonRuntimeException jre) { final JsonExceptionBuilder builder = JsonRuntimeException.newBuilder(jre.getErrorCode()) .message("Error when parsing Json type '" + type + "': " + jre.getMessage()) .cause(jre.getCause()); jre.getDescription().ifPresent(builder::description); jre.getHref().ifPresent(builder::href); // rethrow after enhancing the exception with the type which failed to parse throw (JsonRuntimeException) builder.build(); } } else { throw JsonTypeNotParsableException.newBuilder(type, getClass().getSimpleName()) .dittoHeaders(dittoHeaders) .build(); } }
.<CommandResponse<?>>parse(commandResponse.asObject(), dittoHeaders.toBuilder() .source(instanceField.getKey())
.<CommandResponse<?>>parse(commandResponse.asObject(), dittoHeaders.toBuilder() .source(instanceField.getKey())