Search in sources :

Example 1 with SchemaCaseFormat

use of org.apache.beam.sdk.schemas.annotations.SchemaCaseFormat in project beam by apache.

the class FieldValueTypeInformation method getNameOverride.

public static <T extends AnnotatedElement & Member> String getNameOverride(String original, T member) {
    @Nullable SchemaFieldName fieldName = member.getAnnotation(SchemaFieldName.class);
    @Nullable SchemaCaseFormat caseFormatAnnotation = member.getAnnotation(SchemaCaseFormat.class);
    @Nullable SchemaCaseFormat classCaseFormatAnnotation = member.getDeclaringClass().getAnnotation(SchemaCaseFormat.class);
    if (fieldName != null) {
        if (caseFormatAnnotation != null) {
            throw new RuntimeException(String.format("Cannot define both @SchemaFieldName and @SchemaCaseFormat. From member '%s'.", member.getName()));
        }
        return fieldName.value();
    } else if (caseFormatAnnotation != null) {
        return CaseFormat.LOWER_CAMEL.to(caseFormatAnnotation.value(), original);
    } else if (classCaseFormatAnnotation != null) {
        return CaseFormat.LOWER_CAMEL.to(classCaseFormatAnnotation.value(), original);
    } else {
        return original;
    }
}
Also used : SchemaFieldName(org.apache.beam.sdk.schemas.annotations.SchemaFieldName) SchemaCaseFormat(org.apache.beam.sdk.schemas.annotations.SchemaCaseFormat) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

SchemaCaseFormat (org.apache.beam.sdk.schemas.annotations.SchemaCaseFormat)1 SchemaFieldName (org.apache.beam.sdk.schemas.annotations.SchemaFieldName)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1