private static JsonArray getJsonValueAsArray(JsonValue value) { return (value != null && value.getValueType() == ValueType.ARRAY) ? value.asJsonArray() : null; }
private static List<JsonObject> getJsonValueAsList(JsonValue value) { if (value != null) { if (value.getValueType() == ValueType.ARRAY) { return value.asJsonArray().getValuesAs(JsonObject.class); } else if (value.getValueType() == ValueType.OBJECT) { List<JsonObject> ret = new ArrayList<>(); ret.add(value.asJsonObject()); return ret; } } return null; }
private static JsonArray getJsonArray(JsonObject obj, String prop) throws ChaincodeCollectionConfigurationException { JsonValue ret = obj.get(prop); if (ret == null) { throw new ChaincodeCollectionConfigurationException(format("property %s missing", prop)); } if (ret.getValueType() != JsonValue.ValueType.ARRAY) { throw new ChaincodeCollectionConfigurationException(format("property %s wrong type expected array got %s", prop, ret.getValueType().name())); } return ret.asJsonArray(); }
private static JsonArray getJsonValueAsArray(JsonValue value) { return (value != null && value.getValueType() == ValueType.ARRAY) ? value.asJsonArray() : null; }
private static JsonArray getJsonValueAsArray(JsonValue value) { return (value != null && value.getValueType() == ValueType.ARRAY) ? value.asJsonArray() : null; }
private static List<JsonObject> getJsonValueAsList(JsonValue value) { if (value != null) { if (value.getValueType() == ValueType.ARRAY) { return value.asJsonArray().getValuesAs(JsonObject.class); } else if (value.getValueType() == ValueType.OBJECT) { List<JsonObject> ret = new ArrayList<>(); ret.add(value.asJsonObject()); return ret; } } return null; }
private static List<JsonObject> getJsonValueAsList(JsonValue value) { if (value != null) { if (value.getValueType() == ValueType.ARRAY) { return value.asJsonArray().getValuesAs(JsonObject.class); } else if (value.getValueType() == ValueType.OBJECT) { List<JsonObject> ret = new ArrayList<>(); ret.add(value.asJsonObject()); return ret; } } return null; }
private Object mapValue(final JsonValue value) { switch (value.getValueType()) { case ARRAY: return value.asJsonArray().stream().map(this::mapValue).collect(toList()); case STRING: return JsonString.class.cast(value).getString(); case TRUE: return true; case FALSE: return false; case NUMBER: return JsonNumber.class.cast(value).doubleValue(); case NULL: return null; case OBJECT: default: return value; } } }
@Override public Optional<Function<JsonValue, Stream<ValidationResult.ValidationError>>> create(final ValidationContext model) { final JsonValue value = model.getSchema().get("type"); if (JsonString.class.isInstance(value)) { return Optional.of(new Impl(model.toPointer(), model.getValueProvider(), mapType(JsonString.class.cast(value)).toArray(JsonValue.ValueType[]::new))); } if (JsonArray.class.isInstance(value)) { return Optional.of(new Impl(model.toPointer(), model.getValueProvider(), value.asJsonArray().stream().flatMap(this::mapType).toArray(JsonValue.ValueType[]::new))); } throw new IllegalArgumentException(value + " is neither an array or string nor a string"); }
private JsonObject getJwkFromJwks(final JsonObject jwks) { final JsonValue keys = jwks.getValue("keys"); if (keys == null) { throw new IllegalArgumentException("Invalid JWKS; 'keys' entry is missing."); } switch (keys.getValueType()) { case ARRAY: return getFirstJwk(jwks, keys.asJsonArray()); case OBJECT: return keys.asJsonObject(); default: throw new IllegalArgumentException("Invalid JWKS; 'keys' entry should be an array."); } }
private static JsonArray getJsonArray(JsonObject obj, String prop) throws ChaincodeCollectionConfigurationException { JsonValue ret = obj.get(prop); if (ret == null) { throw new ChaincodeCollectionConfigurationException(format("property %s missing", prop)); } if (ret.getValueType() != JsonValue.ValueType.ARRAY) { throw new ChaincodeCollectionConfigurationException(format("property %s wrong type expected array got %s", prop, ret.getValueType().name())); } return ret.asJsonArray(); }
@Override public Stream<ValidationResult.ValidationError> apply(final JsonValue obj) { if (isNull(obj) && rootCanBeNull) { return Stream.empty(); } final JsonValue value = extractor.apply(obj); if (value == null || JsonValue.ValueType.NULL == value.getValueType() || value.getValueType() != validType) { return Stream.empty(); } switch (value.getValueType()) { case STRING: return onString(JsonString.class.cast(value)); case TRUE: case FALSE: return onBoolean(JsonValue.TRUE.equals(value)); case NUMBER: return onNumber(JsonNumber.class.cast(value)); case OBJECT: return onObject(value.asJsonObject()); case ARRAY: return onArray(value.asJsonArray()); case NULL: return Stream.empty(); default: throw new IllegalArgumentException("Unsupported value type: " + value); } }
@Override public Optional<Function<JsonValue, Stream<ValidationResult.ValidationError>>> create(final ValidationContext model) { return Optional.ofNullable(model.getSchema().get("items")) .map(items -> { switch (items.getValueType()) { case OBJECT: final JsonSchemaValidator objectValidator = factory.newInstance(items.asJsonObject()); return new ItemsValidator(model.toPointer(), model.getValueProvider(), singleton(objectValidator)); case ARRAY: return new ItemsValidator(model.toPointer(), model.getValueProvider(), items.asJsonArray().stream() .filter(it -> it.getValueType() == JsonValue.ValueType.OBJECT) .map(it -> factory.newInstance(it.asJsonObject())) .collect(toList())); default: return null; } }); }
if (min != null) { final double bound = Double.parseDouble(min); if (value.getValueType() == JsonValue.ValueType.ARRAY && value.asJsonArray().size() < bound) { errors.add(MESSAGES.minItems(meta.getPath(), bound, value.asJsonArray().size())); if (max != null) { final double bound = Double.parseDouble(max); if (value.getValueType() == JsonValue.ValueType.ARRAY && value.asJsonArray().size() > bound) { errors.add(MESSAGES.maxItems(meta.getPath(), bound, value.asJsonArray().size())); if (unique != null) { if (value.getValueType() == JsonValue.ValueType.ARRAY) { final JsonArray array = value.asJsonArray(); if (new HashSet<>(array).size() != array.size()) { errors.add(MESSAGES.uniqueItems(meta.getPath()));
private Object toValue(final Object baseInstance, final JsonValue jsonValue, final Adapter converter, final Adapter itemConverter, final Type type, final ObjectConverter.Reader objectConverter, final JsonPointerTracker jsonPointer, final Type rootType) { if (objectConverter != null) { if (jsonValue instanceof JsonObject) { return objectConverter.fromJson((JsonObject) jsonValue, type, this); } else if (jsonValue instanceof JsonArray) { return buildArray(type, jsonValue.asJsonArray(), itemConverter, objectConverter, jsonPointer, rootType); } else { throw new UnsupportedOperationException("Array handling with ObjectConverter currently not implemented"); } } try { return converter == null ? toObject(baseInstance, jsonValue, type, itemConverter, jsonPointer, rootType) : jsonValue.getValueType() == JsonValue.ValueType.STRING ? converter.to(JsonString.class.cast(jsonValue).getString()) : convertTo(converter, jsonValue, jsonPointer); } catch (Exception e) { if (e instanceof MapperException) { throw e; } throw new MapperException(e); } }
private Object toValue(final Object baseInstance, final JsonValue jsonValue, final Adapter converter, final Adapter itemConverter, final Type type, final ObjectConverter.Reader objectConverter, final JsonPointerTracker jsonPointer, final Type rootType) { if (objectConverter != null) { if (jsonValue instanceof JsonObject) { return objectConverter.fromJson((JsonObject) jsonValue, type, this); } else if (jsonValue instanceof JsonArray) { return buildArray(type, jsonValue.asJsonArray(), itemConverter, objectConverter, jsonPointer, rootType); } else { throw new UnsupportedOperationException("Array handling with ObjectConverter currently not implemented"); } } try { return converter == null ? toObject(baseInstance, jsonValue, type, itemConverter, jsonPointer, rootType) : jsonValue.getValueType() == JsonValue.ValueType.STRING ? converter.to(JsonString.class.cast(jsonValue).getString()) : convertTo(converter, jsonValue, jsonPointer); } catch (Exception e) { if (e instanceof MapperException) { throw e; } throw new MapperException(e); } }
.reduce(true, (a, b) -> a && b); case ARRAY: final JsonArray oldArray = oldValue.asJsonArray(); final JsonArray newArray = newValue.asJsonArray(); if (oldArray.size() != newArray.size()) { return false;
case ARRAY: { final List<Object> items = value.asJsonArray().stream().map(it -> mapJson(factory, it)).collect(toList()); builder .withArray(factory