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(); } }