CoderRegistry (Google Cloud Dataflow SDK 1.9.1 API)

Google Cloud Dataflow SDK for Java, version 1.9.1

Class CoderRegistry

    • Constructor Detail

      • CoderRegistry

        public CoderRegistry()
    • Method Detail

      • registerStandardCoders

        public void registerStandardCoders()
        Registers standard Coders with this CoderRegistry.
      • registerCoder

        public void registerCoder(Class<?> clazz,
                                  Class<?> coderClazz)
        Registers coderClazz as the default Coder class to handle encoding and decoding instances of clazz, overriding prior registrations if any exist.

        Supposing T is the static type corresponding to the clazz, then coderClazz should have a static factory method with the following signature:

         public static Coder<T> of(Coder<X> argCoder1, Coder<Y> argCoder2, ...)

        This method will be called to create instances of Coder<T> for values of type T, passing Coders for each of the generic type parameters of T. If T takes no generic type parameters, then the of() factory method should have no arguments.

        If T is a parameterized type, then it should additionally have a method with the following signature:

         public static List<Object> getInstanceComponents(T exampleValue);

        This method will be called to decompose a value during the Coder inference process, to automatically choose Coders for the components.

        clazz - the class of objects to be encoded
        coderClazz - a class with static factory methods to provide Coders
      • registerCoder

        public void registerCoder(Class<?> clazz,
                                  CoderFactory coderFactory)
        Registers coderFactory as the default CoderFactory to produce Coder instances to decode and encode instances of clazz. This will override prior registrations if any exist.
      • registerCoder

        public <T> void registerCoder(Class<T> rawClazz,
                                      Coder<T> coder)
        Register the provided Coder for encoding all values of the specified Class. This will override prior registrations if any exist.

        Not for use with generic rawtypes. Instead, register a CoderFactory via registerCoder(Class, CoderFactory) or ensure your Coder class has the appropriate static methods and register it directly via registerCoder(Class, Class).

      • getDefaultCoders

        public <T> Map<Type,Coder<?>> getDefaultCoders(Class<? extends T> subClass,
                                                                   Class<T> baseClass,
                                                                   Map<Type,? extends Coder<?>> knownCoders)
        Deprecated. this method is not part of the public interface and will be made private
        Returns a Map from each of baseClass's type parameters to the Coder to use by default for it, in the context of subClass's specialization of baseClass.

        If no Coder can be inferred for a particular type parameter, then that type variable will be absent from the returned Map.

        For example, if baseClass is Map.class, where Map<K, V> has type parameters K and V, and subClass extends Map<String, Integer> then the result will map the type variable K to a Coder<String> and the type variable V to a Coder<Integer>.

        The knownCoders parameter can be used to provide known Coders for any of the parameters; these will be used to infer the others.

        Note that inference is attempted for every type variable. For a type MyType<One, Two, Three> inference will be attempted for all of One, Two, Three, even if the requester only wants a Coder for Two.

        For this reason getDefaultCoders (plural) does not throw an exception if a Coder for a particular type variable cannot be inferred, but merely omits the entry from the returned Map. It is the responsibility of the caller (usually getDefaultCoder(<T>) to extract the desired coder or throw a CannotProvideCoderException when appropriate.

        subClass - the concrete type whose specializations are being inferred
        baseClass - the base type, a parameterized class
        knownCoders - a map corresponding to the set of known Coders indexed by parameter name