/** * Factory method that should be used to construct instances. * For some common cases, can reuse canonical instances: currently * this is the case for empty Strings, in future possible for * others as well. If null is passed, will return null. * * @return Resulting {@link TextNode} object, if <b>v</b> * is NOT null; null if it is. */ public static TextNode valueOf(String v) { if (v == null) { return null; } if (v.length() == 0) { return EMPTY_STRING_NODE; } return new TextNode(v); }
/** * Factory method that should be used to construct instances. * For some common cases, can reuse canonical instances: currently * this is the case for empty Strings, in future possible for * others as well. If null is passed, will return null. * * @return Resulting {@link TextNode} object, if <b>v</b> * is NOT null; null if it is. */ public static TextNode valueOf(String v) { if (v == null) { return null; } if (v.length() == 0) { return EMPTY_STRING_NODE; } return new TextNode(v); }
return new DoubleNode(in.readDouble()); case STRING: return new TextNode(in.readString()); case BOOLEAN: return in.readBoolean() ? BooleanNode.TRUE : BooleanNode.FALSE;
/** * Factory method that should be used to construct instances. * For some common cases, can reuse canonical instances: currently * this is the case for empty Strings, in future possible for * others as well. If null is passed, will return null. * * @return Resulting {@link TextNode} object, if <b>v</b> * is NOT null; null if it is. */ public static TextNode valueOf(String v) { if (v == null) { return null; } if (v.length() == 0) { return EMPTY_STRING_NODE; } return new TextNode(v); }
/** * Factory method that should be used to construct instances. * For some common cases, can reuse canonical instances: currently * this is the case for empty Strings, in future possible for * others as well. If null is passed, will return null. * * @return Resulting {@link TextNode} object, if <b>v</b> * is NOT null; null if it is. */ public static TextNode valueOf(String v) { if (v == null) { return null; } if (v.length() == 0) { return EMPTY_STRING_NODE; } return new TextNode(v); }
/** * Factory method that should be used to construct instances. * For some common cases, can reuse canonical instances: currently * this is the case for empty Strings, in future possible for * others as well. If null is passed, will return null. * * @return Resulting {@link TextNode} object, if <b>v</b> * is NOT null; null if it is. */ public static TextNode valueOf(String v) { if (v == null) { return null; } if (v.length() == 0) { return EMPTY_STRING_NODE; } return new TextNode(v); }
@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())); }
return new DoubleNode(in.readDouble()); case STRING: return new TextNode(in.readString()); case BOOLEAN: return in.readBoolean() ? BooleanNode.TRUE : BooleanNode.FALSE;