@SuppressWarnings("squid:S1166") private static String tryToDecodeString(final String s, final JsonParseOptions jsonParseOptions) { try { return decode(s, jsonParseOptions); } catch (final Exception e) { throw JsonFieldSelectorInvalidException.newBuilder() // .fieldSelector(s) // .description("Check if the field selector is correctly URL encoded.") // .cause(e) // .build(); } }
/** * @param jsonFields the json fields to create a new JsonObject from. * @return a null object if {@code jsonFields} is a null json object. Else this returns a new object containing the * given {code jsonFields}. */ public static JsonObject newObject(final Iterable<JsonField> jsonFields) { if (jsonFields instanceof JsonObject && ((JsonValue) jsonFields).isNull()) { return nullObject(); } return newObjectBuilder(jsonFields).build(); }
@Override public JsonObject toJson() { return JsonFactory.newObjectBuilder() .set(JsonFields.CORRELATION_ID, correlationId) .set(JsonFields.PAYLOAD, payload) .build(); }
private static String getMessage(final JsonObject jsonObject) { return jsonObject.getValue(DittoJsonException.JsonFields.MESSAGE) .orElseThrow(() -> JsonMissingFieldException.newBuilder() .fieldName(DittoRuntimeException.JsonFields.MESSAGE.getPointer().toString()).build()); }
@Override public JsonPointer getResourcePath() { final String path = Thing.JsonFields.POLICY_ID.getPointer().toString(); return JsonPointer.of(path); }
private static JsonValue tryToReadJsonValueFrom(final Reader reader) { try { return readJsonValueFrom(reader); } catch (final ParseException | IOException | StackOverflowError e) { throw JsonParseException.newBuilder() .message("Failed to parse JSON value from reader!") .cause(e) .build(); } }
@Override public JsonObject get(final JsonFieldDefinition fieldDefinition) { checkFieldDefinition(fieldDefinition); return get(fieldDefinition.getPointer()); }
@Override public ImmutableJsonArray add(final boolean value, final boolean... furtherValues) { checkFurtherValues(furtherValues); SoftReferencedValueList extendedValueList = valueList.add(JsonValue.of(value)); for (final boolean furtherValue : furtherValues) { extendedValueList = extendedValueList.add(JsonValue.of(furtherValue)); } return new ImmutableJsonArray(extendedValueList); }
/** * Returns a new JSON field selector based on the parsed string which was given to this class' constructor. * * @return a new JSON field selector instance. * @throws IllegalStateException if the JSON field selector string could not be decoded as UTF-8. */ public JsonFieldSelector newJsonFieldSelector() { final List<String> rawJsonKeys = splitAroundComma(jsonFieldSelectorString); final Set<JsonPointer> jsonPointers = flattenToJsonPointers(rawJsonKeys); return ImmutableJsonFieldSelector.of(jsonPointers, jsonFieldSelectorString); } }
/** * Returns a builder for fluently creating instances of {@code JsonRuntimeException}s.. * * @param errorCode a code which uniquely identifies the exception. * @return a new builder for JsonRuntimeException objects. * @throws NullPointerException if {@code errorCode} is {@code null}. * @throws IllegalArgumentException if {@code errorCode} is empty. */ public static JsonExceptionBuilder newBuilder(final String errorCode) { checkErrorCode(errorCode); return new Builder(errorCode); }
@Override public JsonPointer getResourcePath() { final String path = Thing.JsonFields.POLICY_ID.getPointer().toString(); return JsonPointer.of(path); }
@SuppressWarnings("squid:S1166") private static String tryToDecodeString(final String s, final JsonParseOptions jsonParseOptions) { try { return decode(s, jsonParseOptions); } catch (final Exception e) { throw JsonFieldSelectorInvalidException.newBuilder() // .fieldSelector(s) // .description("Check if the field selector is correctly URL encoded.") // .cause(e) // .build(); } }
/** * Returns a builder for fluently creating instances of {@code JsonRuntimeException}s.. * * @param errorCode a code which uniquely identifies the exception. * @return a new builder for JsonRuntimeException objects. * @throws NullPointerException if {@code errorCode} is {@code null}. * @throws IllegalArgumentException if {@code errorCode} is empty. */ public static JsonExceptionBuilder newBuilder(final String errorCode) { checkErrorCode(errorCode); return new Builder(errorCode); }