Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/794#discussion_r31827450
  
    --- Diff: docs/apis/best_practices.md ---
    @@ -155,3 +155,41 @@ public static final class Tokenizer extends 
RichFlatMapFunction<String, Tuple2<S
                // .. do more ..
     {% endhighlight %}
     
    +
    +## Register a custom serializer for your Flink program
    +
    +If you use a custom type in your Flink program which cannot be serialized 
by the
    +Flink type serializer, Flink falls back to using the generic Kryo
    +serializer. You may register your own serializer or a serialization system 
like
    +Google Protobuf or Apache Thrift with Kryo. To do that, simply register 
the type
    +class and the serializer in the `ExecutionConfig` of your Flink program.
    +
    +
    +{% highlight java %}
    +final ExecutionEnvironment env = 
ExecutionEnvironment.getExecutionEnvironment();
    +
    +// register the class of the serializer as serializer for a type
    +env.getConfig().registerTypeWithKryoSerializer(MyCustomType.class, 
MyCustomSerializer.class);
    +
    +// register an instance as serializer for a type
    +MySerializer mySerializer = new MySerializer();
    +env.getConfig().registerTypeWithKryoSerializer(MyCustomType.class, 
mySerializer);
    +{% endhighlight %}
    +
    +Note that your custom serializer has to extend Kryo's Serializer class. In 
the
    +case of Google Protobuf or Apache Thrift, this has already been done for
    +you:
    +
    +{% highlight java %}
    +
    +final ExecutionEnvironment env = 
ExecutionEnvironment.getExecutionEnvironment();
    +
    +// register the Google Protobuf serializer with Kryo
    +env.getConfig().registerTypeWithKryoSerializer(MyCustomType.class, 
ProtobufSerializer.class);
    +
    +// register the serializer included with Apache Thrift as the standard 
serializer
    +// TBaseSerializer states it should be initalized as a default Kryo 
serializer
    +env.getConfig().addDefaultKryoSerializer(MyCustomType.class, 
TBaseSerializer.class);
    +env.getConfig().registerTypeWithKryoSerializer(MyCustomType.class, 
TMessage.class);
    --- End diff --
    
    this seems incorrect


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to