private boolean hasExpectedValueType(final JsonValue jsonValue) { return jsonValue.isNull() || checkJavaTypeFunction.apply(jsonValue); }
private boolean hasExpectedValueType(final JsonValue jsonValue) { return jsonValue.isNull() || checkJavaTypeFunction.apply(jsonValue); }
@Nullable @Override protected T getAsJavaType(final JsonValue jsonValue, final Function<JsonValue, T> mappingFunction) { if (jsonValue.isNull()) { return null; } return mappingFunction.apply(jsonValue); }
@Nullable @Override protected T getAsJavaType(final JsonValue jsonValue, final Function<JsonValue, T> mappingFunction) { if (jsonValue.isNull()) { return null; } return mappingFunction.apply(jsonValue); }
/** * Returns a {@code Predicate} for testing if the value of a JSON field is null. * * @return the predicate. * @see JsonValue#isNull() */ static Predicate<JsonField> isValueNonNull() { return jsonField -> !jsonField.getValue().isNull(); }
/** * Returns a {@code Predicate} for testing if the value of a JSON field is null. * * @return the predicate. * @see JsonValue#isNull() */ static Predicate<JsonField> isValueNonNull() { return jsonField -> !jsonField.getValue().isNull(); }
private boolean violatesThreshold(final JsonPointer key, final JsonValue value, final int overhead, final int threshold) { return null != value && value.isString() && !value.isNull() && threshold < value.asString().length() + totalOverhead(key, overhead); }
private boolean violatesThreshold(final JsonPointer key, final JsonValue value, final int overhead, final int threshold) { return null != value && value.isString() && !value.isNull() && threshold < value.asString().length() + totalOverhead(key, overhead); }
/** * @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(); }
private static JsonObject setFieldInHierarchy(final JsonObject target, final JsonPointer pointer, final JsonField jsonField) { if (1 >= pointer.getLevelCount()) { return target.set(jsonField); } final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY); final JsonObject newTarget = target.getValue(rootKey) .filter(JsonValue::isObject) .filter(jsonValue -> !jsonValue.isNull()) .map(JsonValue::asObject) .orElseGet(ImmutableJsonObject::empty); // let the recursion begin ]:-) return target.setValue(rootKey, setFieldInHierarchy(newTarget, pointer.nextLevel(), jsonField)); }
private static JsonObject setFieldInHierarchy(final JsonObject target, final JsonPointer pointer, final JsonField jsonField) { if (1 >= pointer.getLevelCount()) { return target.set(jsonField); } final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY); final JsonObject newTarget = target.getValue(rootKey) .filter(JsonValue::isObject) .filter(jsonValue -> !jsonValue.isNull()) .map(JsonValue::asObject) .orElseGet(ImmutableJsonObject::empty); // let the recursion begin ]:-) return target.setValue(rootKey, setFieldInHierarchy(newTarget, pointer.nextLevel(), jsonField)); }
@Override public S isNullLiteral() { isNotNull(); assertThat(actual.isNull()).overridingErrorMessage( "Expected JSON value <%s> to be null literal but it was not.", actual).isTrue(); return myself; }
@Override public S isNotNullLiteral() { isNotNull(); assertThat(actual.isNull()) .overridingErrorMessage("Expected JSON value <%s> not to be null literal but it was.", actual) .isFalse(); return myself; }
private static Collection<ResourcePermissions> createEntriesForFeatureProperty(final CharSequence featureId, final JsonPointer propertyPointer, final JsonValue propertyValue, final Enforcer policyEnforcer) { final Collection<ResourcePermissions> result = new HashSet<>(3); if (propertyValue.isObject() && !propertyValue.isNull()) { final JsonObject propertyValueJsonObject = propertyValue.asObject(); // Recursion! propertyValueJsonObject.forEach(subField -> result.addAll( createEntriesForFeatureProperty(featureId, propertyPointer.addLeaf(subField.getKey()), subField.getValue(), policyEnforcer))); } else { result.add(FeaturePropertyResourcePermissions.getInstance(featureId, propertyPointer, propertyValue, policyEnforcer)); } return result; }
private static Collection<ResourcePermissions> createEntriesForAttribute(final JsonPointer attributePointer, final JsonValue attributeValue, final Enforcer policyEnforcer) { final Collection<ResourcePermissions> result = new HashSet<>(3); if (attributeValue.isObject() && !attributeValue.isNull()) { final JsonObject jsonObject = attributeValue.asObject(); // Recursion! jsonObject.forEach( subField -> result.addAll(createEntriesForAttribute(attributePointer.addLeaf(subField.getKey()), subField.getValue(), policyEnforcer))); } else { result.add(AttributeResourcePermissions.getInstance(attributePointer, attributeValue, policyEnforcer)); } return result; }
private static Collection<ResourcePermissions> createEntriesForAttribute(final JsonPointer attributePointer, final JsonValue attributeValue, final Enforcer policyEnforcer) { final Collection<ResourcePermissions> result = new HashSet<>(3); if (attributeValue.isObject() && !attributeValue.isNull()) { final JsonObject jsonObject = attributeValue.asObject(); // Recursion! jsonObject.forEach( subField -> result.addAll(createEntriesForAttribute(attributePointer.addLeaf(subField.getKey()), subField.getValue(), policyEnforcer))); } else { result.add(AttributeResourcePermissions.getInstance(attributePointer, attributeValue, policyEnforcer)); } return result; }
private static Collection<ResourcePermissions> createEntriesForFeatureProperty(final CharSequence featureId, final JsonPointer propertyPointer, final JsonValue propertyValue, final Enforcer policyEnforcer) { final Collection<ResourcePermissions> result = new HashSet<>(3); if (propertyValue.isObject() && !propertyValue.isNull()) { final JsonObject propertyValueJsonObject = propertyValue.asObject(); // Recursion! propertyValueJsonObject.forEach(subField -> result.addAll( createEntriesForFeatureProperty(featureId, propertyPointer.addLeaf(subField.getKey()), subField.getValue(), policyEnforcer))); } else { result.add(FeaturePropertyResourcePermissions.getInstance(featureId, propertyPointer, propertyValue, policyEnforcer)); } return result; }
private void addInternalAttributes(final String path, final JsonValue jsonValue) { if (jsonValue == null || jsonValue.isNull()) { attributeInternally(path, null); } else if (jsonValue.isString()) { attributeInternally(path, jsonValue.asString()); } else if (jsonValue.isBoolean()) { attributeInternally(path, jsonValue.asBoolean()); } else if (jsonValue.isNumber()) { addNumberAttribute(path, jsonValue); } else if (jsonValue.isObject()) { jsonValue.asObject().getKeys().forEach(key -> // addInternalAttributes(path + PersistenceConstants.SLASH + key, jsonValue.asObject().getValue(key).orElse(null))); } }
private void addInternalAttributes(final String path, final JsonValue jsonValue) { if ((jsonValue == null) || jsonValue.isNull()) { attributeInternally(path, null); } else if (jsonValue.isString()) { attributeInternally(path, jsonValue.asString()); } else if (jsonValue.isBoolean()) { attributeInternally(path, jsonValue.asBoolean()); } else if (jsonValue.isNumber()) { addNumberAttribute(path, jsonValue); } else if (jsonValue.isObject()) { jsonValue.asObject().getKeys().forEach(key -> // addInternalAttributes(path + PersistenceConstants.SLASH + key, jsonValue.asObject().getValue(key).orElse(null))); } }
private void addInternalFeatures(final String path, final JsonValue jsonValue, final String featureId) { if ((jsonValue == null) || jsonValue.isNull()) { featureInternally(path, null, featureId); } else if (jsonValue.isString()) { featureInternally(path, jsonValue.asString(), featureId); } else if (jsonValue.isBoolean()) { featureInternally(path, jsonValue.asBoolean(), featureId); } else if (jsonValue.isNumber()) { addNumberFeature(path, jsonValue, featureId); } else if (jsonValue.isObject()) { jsonValue.asObject().getKeys().forEach(name -> // addInternalFeatures(path + "/" + name, jsonValue.asObject().getValue(name).orElse(null), featureId)); } }