/** * Test whether a numeric instance is a long * * <p>We use both a test on the instance type and Jackson's {@link * JsonNode#canConvertToLong()}. The first test is needed since the * latter method will also return true if the value is a decimal which * integral part fits into a long, and we don't want that.</p> * * @param node the node to test * @return true if both conditions are true */ private static boolean valueIsLong(final JsonNode node) { return NodeType.getNodeType(node) == NodeType.INTEGER && node.canConvertToLong(); } }
private DraftV4TypeDigester() { super("type", NodeType.ARRAY, NodeType.values()); }
public DraftV4TypeValidator(final JsonNode digest) { super("type"); for (final JsonNode node: digest.get(keyword)) types.add(NodeType.fromName(node.textValue())); }
@Override public JsonNode digest(final JsonNode schema) { final ObjectNode ret = FACTORY.objectNode(); final ArrayNode allowedTypes = FACTORY.arrayNode(); ret.put(keyword, allowedTypes); final JsonNode node = schema.get(keyword); final EnumSet<NodeType> typeSet = EnumSet.noneOf(NodeType.class); if (node.isTextual()) // Single type typeSet.add(NodeType.fromName(node.textValue())); else // More than one type for (final JsonNode element: node) typeSet.add(NodeType.fromName(element.textValue())); if (typeSet.contains(NodeType.NUMBER)) typeSet.add(NodeType.INTEGER); /* * Note that as this is an enumset, order is guaranteed */ for (final NodeType type: typeSet) allowedTypes.add(type.toString()); return ret; } }
if (NodeType.fromName(s) == null) report.error(newMsg(tree, bundle, "common.typeDisallow.primitiveType.unknown") type = NodeType.getNodeType(element); uniqueElements = set.add(EQUIVALENCE.wrap(element)); if (type != NodeType.STRING) { if (NodeType.fromName(found) == null) report.error(newMsg(tree, bundle, "common.typeDisallow.primitiveType.unknown")
simpleTypes.add(type.toString());
@Override protected int doHash(final SchemaContext t) { return t.getSchema().hashCode() ^ t.getInstanceType().hashCode(); } }
if (NodeType.fromName(s) == null) report.error(newMsg(tree, bundle, "common.typeDisallow.primitiveType.unknown") type = NodeType.getNodeType(element); uniqueElements = set.add(EQUIVALENCE.wrap(element)); if (type != NodeType.STRING) { if (NodeType.fromName(found) == null) report.error(newMsg(tree, bundle, "common.typeDisallow.primitiveType.unknown")
private static boolean alreadySupportsNullType(final JsonNode schemaObject) { final String nullType = NodeType.NULL.toString(); final JsonNode typeNode = schemaObject.get(TYPE_KEY); if (typeNode.isTextual()) { return nullType.equals(typeNode.asText()); } else if (typeNode.isArray()) { final ArrayNode typeNodeArr = (ArrayNode) typeNode; for (final JsonNode typeElem : typeNodeArr) { if (nullType.equals(typeElem.asText())) { return true; } } } return false; }
private static boolean valueIsLong(final JsonNode node) { if (!node.canConvertToLong()) return false; if (NodeType.getNodeType(node) == NodeType.INTEGER) return true; return node.decimalValue().remainder(BigDecimal.ONE) .compareTo(BigDecimal.ZERO) == 0; }
public DraftV3TypeKeywordDigester(final String keyword) { super(keyword, NodeType.ARRAY, NodeType.values()); }
if (NodeType.fromName(s) == null) report.error(newMsg(tree, bundle, "common.typeDisallow.primitiveType.unknown") type = NodeType.getNodeType(element); uniqueElements = set.add(EQUIVALENCE.wrap(element)); if (type != NodeType.STRING) { if (NodeType.fromName(found) == null) report.error(newMsg(tree, bundle, "common.typeDisallow.primitiveType.unknown")
private static void putType(final EnumSet<NodeType> types, final String s) { if (ANY.equals(s)) { types.addAll(EnumSet.allOf(NodeType.class)); return; } final NodeType type = NodeType.fromName(s); types.add(type); if (type == NodeType.NUMBER) types.add(NodeType.INTEGER); } }
private static void setupNullableTypes(final JsonNode schemaObject) { // If the node is marked as nullable, and the type for this node is not // already "null", then we need to turn the "type" field into a list of // the currently specified type and "null", so that it will be properly // handled by the JSON-schema validation routine. final String nullType = NodeType.NULL.toString(); schemaObject .findParents(TYPE_KEY) .stream() .filter(jsonNode -> jsonNode.path(NULLABLE_KEY).asBoolean(false)) .filter(jsonNode -> !alreadySupportsNullType(jsonNode)) .forEach(jsonNode -> { final JsonNode type = jsonNode.get(TYPE_KEY); if (type.isTextual()) { // If we are here, it means the type is a value // like "string". So we need to transform it into // an array type like [ "null", "string" ]. ((ObjectNode) jsonNode).putArray(TYPE_KEY).add(nullType).add(type); } else if (type.isArray()) { // If we are here, it means the type is already an // array of types, like [ "integer", "string" ]. We // just need to append the null type on the end. ((ArrayNode) type).add(nullType); } }); }
key = entry.getKey(); value = entry.getValue(); type = NodeType.getNodeType(value); switch (type) { case OBJECT:
public DraftV4TypeDigesterTest() throws IOException { super("type", NodeType.ARRAY, NodeType.values()); } }
protected DraftV3TypeKeywordValidator(final String keyword, final JsonNode digested) { super(keyword); for (final JsonNode element: digested.get(keyword)) types.add(NodeType.fromName(element.textValue())); for (final JsonNode element: digested.get("schemas")) schemas.add(element.intValue()); }
public SchemaContext(final FullData data) { schema = data.getSchema(); final JsonTree tree = data.getInstance(); instanceType = tree != null ? NodeType.getNodeType(tree.getNode()) : null; }
public NotDigesterTest() throws IOException { super("not", NodeType.ARRAY, NodeType.values()); } }
private static boolean typeIsValid(final String s) { return ANY.equals(s) || NodeType.fromName(s) != null; } }