public static class R12 { // fields @AvroSchema("\"int\"") Object x; @AvroSchema("{\"type\":\"array\",\"items\":[\"null\",\"string\"]}") List<String> strings; }
/** Create a schema for a field. */ protected Schema createFieldSchema(Field field, Map<String, Schema> names) { AvroEncode enc = field.getAnnotation(AvroEncode.class); if (enc != null) try { return enc.using().newInstance().getSchema(); } catch (Exception e) { throw new AvroRuntimeException("Could not create schema from custom serializer for " + field.getName()); } AvroSchema explicit = field.getAnnotation(AvroSchema.class); if (explicit != null) // explicit schema return Schema.parse(explicit.value()); Schema schema = createSchema(field.getGenericType(), names); if (field.isAnnotationPresent(Stringable.class)) { // Stringable schema = Schema.create(Schema.Type.STRING); } if (field.isAnnotationPresent(Nullable.class)) // nullable schema = makeNullable(schema); return schema; }
/** Create a schema for a field. */ protected Schema createFieldSchema(Field field, Map<String, Schema> names) { AvroEncode enc = field.getAnnotation(AvroEncode.class); if (enc != null) try { return enc.using().newInstance().getSchema(); } catch (Exception e) { throw new AvroRuntimeException("Could not create schema from custom serializer for " + field.getName()); } AvroSchema explicit = field.getAnnotation(AvroSchema.class); if (explicit != null) // explicit schema return Schema.parse(explicit.value()); Union union = field.getAnnotation(Union.class); if (union != null) return getAnnotatedUnion(union, names); Schema schema = createSchema(field.getGenericType(), names); if (field.isAnnotationPresent(Stringable.class)) { // Stringable schema = Schema.create(Schema.Type.STRING); } if (field.isAnnotationPresent(Nullable.class)) // nullable schema = makeNullable(schema); return schema; }
@AvroSchema("\"int\"") // message value Object foo(@AvroSchema("\"int\"")Object x); // message param }
Annotation annotation = annotations[i][j]; if (annotation instanceof AvroSchema) // explicit schema paramSchema = Schema.parse(((AvroSchema)annotation).value()); else if (annotation instanceof Union) // union paramSchema = getAnnotatedUnion(((Union)annotation), names); response = Schema.parse(explicit.value());
@AvroSchema("\"null\"") // record public class R13 {}
Annotation annotation = annotations[i][j]; if (annotation instanceof AvroSchema) // explicit schema paramSchema = Schema.parse(((AvroSchema)annotation).value()); else if (annotation instanceof Union) // union paramSchema = getAnnotatedUnion(((Union)annotation), names); response = Schema.parse(explicit.value());
private static class HasGenericRecord { @AvroSchema( "{\"name\": \"bar\", \"type\": \"record\", \"fields\": [" + "{\"name\": \"foo\", \"type\": \"int\"}]}") GenericRecord genericRecord; }
return Schema.parse(explicit.value()); if (CharSequence.class.isAssignableFrom(c)) // String return Schema.create(Schema.Type.STRING);
private static class HasCustomSchema { @AvroSchema( "{\"name\": \"bar\", \"type\": \"record\", \"fields\": [" + "{\"name\": \"foo\", \"type\": \"int\"}]}") int withCustomSchema; }
return Schema.parse(explicit.value()); if (CharSequence.class.isAssignableFrom(c)) // String return Schema.create(Schema.Type.STRING);
private static class GenericWithAnnotation<T> { @AvroSchema("[\"string\", \"int\"]") private T onlySomeTypesAllowed; public GenericWithAnnotation(T value) { onlySomeTypesAllowed = value; } // For deserialization only @SuppressWarnings("unused") protected GenericWithAnnotation() {} @Override public boolean equals(Object other) { return other instanceof GenericWithAnnotation && onlySomeTypesAllowed.equals(((GenericWithAnnotation<?>) other).onlySomeTypesAllowed); } @Override public int hashCode() { return Objects.hash(getClass(), onlySomeTypesAllowed); } }
/** Create a schema for a field. */ protected Schema createFieldSchema(Field field, Map<String, Schema> names) { AvroEncode enc = field.getAnnotation(AvroEncode.class); if (enc != null) try { return enc.using().newInstance().getSchema(); } catch (Exception e) { throw new AvroRuntimeException("Could not create schema from custom serializer for " + field.getName()); } AvroSchema explicit = field.getAnnotation(AvroSchema.class); if (explicit != null) // explicit schema return Schema.parse(explicit.value()); Schema schema = createSchema(field.getGenericType(), names); if (field.isAnnotationPresent(Stringable.class)) { // Stringable schema = Schema.create(Schema.Type.STRING); } if (field.isAnnotationPresent(Nullable.class)) // nullable schema = makeNullable(schema); return schema; }
Annotation annotation = annotations[i][j]; if (annotation instanceof AvroSchema) // explicit schema paramSchema = Schema.parse(((AvroSchema)annotation).value()); else if (annotation instanceof Union) // union paramSchema = getAnnotatedUnion(((Union)annotation), names); response = Schema.parse(explicit.value());
return Schema.parse(explicit.value()); if (CharSequence.class.isAssignableFrom(c)) // String return Schema.create(Schema.Type.STRING);