use of org.codehaus.jackson.node.TextNode in project cdap by caskdata.
the class SchemaTest method testAvroRecordSchema.
@Test
public void testAvroRecordSchema() throws Exception {
org.apache.avro.Schema avroStringSchema = org.apache.avro.Schema.create(org.apache.avro.Schema.Type.STRING);
org.apache.avro.Schema avroIntSchema = org.apache.avro.Schema.create(org.apache.avro.Schema.Type.INT);
org.apache.avro.Schema schema = org.apache.avro.Schema.createRecord("UserInfo", "Describes user information", "org.example.schema", false);
List<org.apache.avro.Schema.Field> fields = new ArrayList<>();
org.apache.avro.Schema.Field field = new org.apache.avro.Schema.Field("username", avroStringSchema, "Field represents username", new TextNode("unknown"));
fields.add(field);
field = new org.apache.avro.Schema.Field("age", avroIntSchema, "Field represents age of user", new IntNode(-1));
fields.add(field);
schema.setFields(fields);
Schema parsedSchema = Schema.parseJson(schema.toString());
Assert.assertTrue("UserInfo".equals(parsedSchema.getRecordName()));
Assert.assertEquals(2, parsedSchema.getFields().size());
Schema.Field parsedField = parsedSchema.getFields().get(0);
Assert.assertTrue("username".equals(parsedField.getName()));
Assert.assertTrue("STRING".equals(parsedField.getSchema().getType().toString()));
parsedField = parsedSchema.getFields().get(1);
Assert.assertTrue("age".equals(parsedField.getName()));
Assert.assertTrue("INT".equals(parsedField.getSchema().getType().toString()));
}
use of org.codehaus.jackson.node.TextNode in project neo4j by neo4j.
the class AbstractRESTInteraction method getValue.
private Object getValue(JsonNode valueNode) {
Object value;
if (valueNode instanceof TextNode) {
value = valueNode.asText();
} else if (valueNode instanceof ObjectNode) {
value = mapValue(valueNode.getFieldNames(), valueNode);
} else if (valueNode instanceof ArrayNode) {
ArrayNode aNode = (ArrayNode) valueNode;
ArrayList<String> listValue = new ArrayList<>(aNode.size());
for (int j = 0; j < aNode.size(); j++) {
listValue.add(aNode.get(j).asText());
}
value = listValue;
} else if (valueNode instanceof IntNode) {
value = valueNode.getIntValue();
} else if (valueNode instanceof LongNode) {
value = valueNode.getLongValue();
} else if (valueNode.isNull()) {
return null;
} else {
throw new RuntimeException(String.format("Unhandled REST value type '%s'. Need String (TextNode), List (ArrayNode), Object (ObjectNode), long (LongNode), or int (IntNode).", valueNode.getClass()));
}
return value;
}
Aggregations