Annotation Type SchemaCreate


  • @Documented
    @Retention(RUNTIME)
    @Target({CONSTRUCTOR,METHOD})
    @Experimental(SCHEMAS)
    public @interface SchemaCreate
    Can be put on a constructor or a static method, in which case that constructor or method will be used to created instance of the class by Beam's schema code.

    For example, the following Java POJO.

    
     @DefaultSchema(JavaBeanSchema.class)
      class MyClass {
        public final String user;
        public final int age;
    
       @SchemaCreate
        public MyClass(String user, int age) {
          this.user = user;
          this.age = age;
        }
      }
     

    This tells Beam that this constructor can be used to construct instances. Beam will match up the names of the constructor arguments to schema fields in order to decide how to create the class from a Row.

    This can also be used to annotate a static factory method on the class. For example:

    
     @DefaultSchema(JavaBeanSchema.class)
      class MyClass {
        public final String user;
        public final int age;
    
        private MyClass(String user, int age) { this.user = user; this.age = age; }
    
       @SchemaCreate
        public static MyClass create(String user, int age) {
          return new MyClass(user, age);
        }
     }