/** Return the defined properties that have string values. */ @Deprecated public Map<String,String> getProps() { Map<String,String> result = new LinkedHashMap<String,String>(); for (Map.Entry<String,JsonNode> e : props.entrySet()) if (e.getValue().isTextual()) result.put(e.getKey(), e.getValue().getTextValue()); return result; }
/** * Returns the value of the named, string-valued property in this schema. * Returns <tt>null</tt> if there is no string-valued property with that name. */ public String getProp(String name) { JsonNode value = getJsonProp(name); return value != null && value.isTextual() ? value.getTextValue() : null; }
static Set<String> parseAliases(JsonNode node) { JsonNode aliasesNode = node.get("aliases"); if (aliasesNode == null) return null; if (!aliasesNode.isArray()) throw new SchemaParseException("aliases not an array: "+node); Set<String> aliases = new LinkedHashSet<String>(); for (JsonNode aliasNode : aliasesNode) { if (!aliasNode.isTextual()) throw new SchemaParseException("alias not a string: "+aliasNode); aliases.add(aliasNode.getTextValue()); } return aliases; }
@Override protected void customizeType(Record record, Schema fieldTypeSchema) { if (record != null && eventClassTypes.contains(record.getSchema().getName())) { JsonNode classTypeNode = fieldTypeSchema.getJsonProp(CLASS_TYPE); Schema enumSchema = record.getSchema().getField(CLASS_TYPE).schema(); if (classTypeNode != null && classTypeNode.isTextual()) { record.put(CLASS_TYPE, new GenericData.EnumSymbol(enumSchema, classTypeNode.asText().toUpperCase())); } else { record.put(CLASS_TYPE, new GenericData.EnumSymbol(enumSchema, OBJECT)); } } }
} else if (node.isTextual()) { return node.asText(); } else if (node.isNumber()) {
@Override protected void customizeFormField(Record fieldType, Field field) { if (fieldType.getSchema().getName().equals(ARRAY_FIELD_TYPE)) { JsonNode overrideStrategyNode = field.getJsonProp(OVERRIDE_STRATEGY); Schema overrideStrategySchema = fieldType.getSchema().getField(OVERRIDE_STRATEGY).schema(); if (overrideStrategyNode != null && overrideStrategyNode.isTextual()) { fieldType.put(OVERRIDE_STRATEGY, new GenericData.EnumSymbol( overrideStrategySchema, overrideStrategyNode.asText().toUpperCase())); } else { fieldType.put(OVERRIDE_STRATEGY, new GenericData.EnumSymbol( overrideStrategySchema, OverrideStrategy.REPLACE.name())); } } }
if(defaultJson.isTextual()) { break; break; case STRING: if(!defaultJson.isTextual()) { expectedVal = "string"; if(defaultJson.isTextual()) { if(schema.hasEnumSymbol(defaultJson.getTextValue())) { break; break; case FIXED: if(defaultJson.isTextual()) { byte[] fixed = defaultJson.getValueAsText().getBytes(); if(fixed.length == schema.getFixedSize()) {
if (!object.has(TYPE) || !object.get(TYPE).isTextual() || !object.get(TYPE).getTextValue().equals("record")) { throw new IllegalArgumentException("The data provided is not a record!"); if (!object.has(NAMESPACE) || !object.get(NAMESPACE).isTextual()) { throw new IllegalArgumentException("No namespace specified!"); } else if (!object.has(NAME) || !object.get(NAME).isTextual()) { throw new IllegalArgumentException("No name specified!"); } else { } else { for (JsonNode child : object.get(DEPENDENCIES)) { if (!child.isObject() || !child.has(FQN) || !child.get(FQN).isTextual() || !child.has(VERSION) || !child.get(VERSION).isInt()) { throw new IllegalArgumentException("Illegal dependency format!");
case ENUM: case FIXED: return defaultValue.isTextual(); case INT: case LONG:
@Test public void testToJson() throws IOException { GlobalMetadata m = new GlobalMetadata(); m.addTransferEncoding("foo"); m.addTransferEncoding("bar"); byte[] utf8 = m.toJsonUtf8(); String parsed = new String(utf8, StandardCharsets.UTF_8); JsonNode root = new ObjectMapper().readTree(parsed); Assert.assertTrue(root.isObject()); Iterator<JsonNode> children = root.getElements(); int numChildren = 0; while (children.hasNext()) { children.next(); numChildren++; } Assert.assertEquals(numChildren, 3, "expected only 3 child nodes - file, dataset, id"); Assert.assertEquals(root.get("file").size(), 0, "expected no children in file node"); Assert.assertTrue(root.get("id").isTextual(), "expected ID to be textual"); JsonNode transferEncoding = root.get("dataset").get("Transfer-Encoding"); Assert.assertEquals(transferEncoding.size(), m.getTransferEncoding().size()); for (int i = 0; i < m.getTransferEncoding().size(); i++) { Assert.assertEquals(transferEncoding.get(i).getTextValue(), m.getTransferEncoding().get(i)); } }
return (float) jsonNode.asDouble(); } else if (jsonNode.isTextual()) { if (schema == null || schema.getType().equals(Schema.Type.STRING) || schema.getType().equals(Schema.Type.ENUM)) {
if (fieldNode.isTextual()) { return fieldNode.getTextValue();
if (schema.isTextual()) { // name Schema result = names.get(schema.getTextValue()); if (result == null) if (fieldTypeNode == null) throw new SchemaParseException("No field type: "+field); if (fieldTypeNode.isTextual() && names.get(fieldTypeNode.getTextValue()) == null) throw new SchemaParseException && (Type.FLOAT.equals(fieldSchema.getType()) || Type.DOUBLE.equals(fieldSchema.getType())) && defaultValue.isTextual()) defaultValue = new DoubleNode(Double.valueOf(defaultValue.getTextValue()));
if (fieldNode.isTextual()) { return fieldNode.getTextValue();
break; case FIXED: if (!n.isTextual()) throw new AvroTypeException("Non-string default value for fixed: "+n); byte[] bb = n.getTextValue().getBytes("ISO-8859-1"); break; case STRING: if (!n.isTextual()) throw new AvroTypeException("Non-string default value for string: "+n); e.writeString(n.getTextValue()); break; case BYTES: if (!n.isTextual()) throw new AvroTypeException("Non-string default value for bytes: "+n); e.writeBytes(n.getTextValue().getBytes("ISO-8859-1"));
return byDefault.asLong(); if (byDefault.isTextual()) { Schema enumSchema = AvroUtils.getSchemaByType(schemaNode, Type.ENUM); if (enumSchema != null) {
if (jsonNode.isTextual()) return jsonNode.getTextValue(); else
@Override public String apply(final JsonNode input) { if (!input.isTextual()) { throw new IllegalStateException("found node that is not a string " + input.toString()); } return input.getTextValue(); } });
public static String getString(JsonNode node, String prop) throws JsonFormatException { if (node.get(prop) == null || node.get(prop).isNull()) { throw new JsonFormatException("Missing required property: " + prop); } if (!node.get(prop).isTextual()) { throw new JsonFormatException("Not a string property: " + prop); } return node.get(prop).getTextValue(); }
private Object extractId(JsonNode idNode) { if (idNode == null) return null; if (idNode.isNumber()) return idNode.getNumberValue(); if (idNode.isTextual()) return idNode.getTextValue(); if (idNode.isNull()) return null; throw new IllegalArgumentException("Not a valid id type: " + idNode); } }