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); }
@Override public JsonNode digest(final JsonNode schema) { final ObjectNode ret = FACTORY.objectNode(); final ArrayNode simpleTypes = FACTORY.arrayNode(); ret.put(keyword, simpleTypes); final ArrayNode schemas = FACTORY.arrayNode(); ret.put("schemas", schemas); final JsonNode node = schema.get(keyword); final EnumSet<NodeType> set = EnumSet.noneOf(NodeType.class); if (node.isTextual()) // Single type putType(set, node.textValue()); else { // More than one type, and possibly schemas final int size = node.size(); JsonNode element; for (int index = 0; index < size; index++) { element = node.get(index); if (element.isTextual()) putType(set, element.textValue()); else schemas.add(index); } } /* * If all types are there, no need to collect schemas */ if (EnumSet.complementOf(set).isEmpty()) schemas.removeAll(); /* * Note that as this is an enumset, order is guaranteed */ for (final NodeType type : set) simpleTypes.add(type.toString()); return ret; }
private static Object valueToArgument(final JsonNode value) { final NodeType type = NodeType.getNodeType(value); switch (type) { case STRING: return value.textValue(); case INTEGER: return value.bigIntegerValue(); case NUMBER: case NULL: case OBJECT: case ARRAY: return value; case BOOLEAN: return value.booleanValue(); // case ARRAY: // final List<Object> list = Lists.newArrayList(); // for (final JsonNode element: value) // list.add(valueToArgument(element)); // return list; default: throw new UnsupportedOperationException(); } }
public AnyOfDigesterTest() throws IOException { super("anyOf", NodeType.ARRAY, NodeType.values()); }
public DraftV3TypeKeywordDigester(final String keyword) { super(keyword, NodeType.ARRAY, NodeType.values()); }