Json format #

To use the JSON format you need to add the Flink JSON dependency to your project:


For PyFlink users, you could use it directly in your jobs.

Flink supports reading/writing JSON records via the JsonSerializationSchema/JsonDeserializationSchema. These utilize the Jackson library, and support any type that is supported by Jackson, including, but not limited to, POJOs and ObjectNode.

The JsonDeserializationSchema can be used with any connector that supports the DeserializationSchema.

For example, this is how you use it with a KafkaSource to deserialize a POJO:

JsonDeserializationSchema<SomePojo> jsonFormat = new JsonDeserializationSchema<>(SomePojo.class);
KafkaSource<SomePojo> source =

The JsonSerializationSchema can be used with any connector that supports the SerializationSchema.

For example, this is how you use it with a KafkaSink to serialize a POJO:

JsonSerializationSchema<SomePojo> jsonFormat = new JsonSerializationSchema<>();
KafkaSink<SomePojo> source =
            new KafkaRecordSerializationSchemaBuilder<>()

Custom Mapper #

Both schemas have constructors that accept a SerializableSupplier<ObjectMapper>, acting a factory for object mappers. With this factory you gain full control over the created mapper, and can enable/disable various Jackson features or register modules to extend the set of supported types or add additional functionality.

JsonSerializationSchema<SomeClass> jsonFormat = new JsonSerializationSchema<>(
    () -> new ObjectMapper()
        .registerModule(new ParameterNamesModule());

Python #

In PyFlink, JsonRowSerializationSchema and JsonRowDeserializationSchema are built-in support for Row type. Here are examples on how to use it in KafkaSource and KafkaSink:

row_type_info = Types.ROW_NAMED(['name', 'age'], [Types.STRING(), Types.INT()])
json_format = JsonRowDeserializationSchema.builder().type_info(row_type_info).build()

source = KafkaSource.builder() \
    .set_value_only_deserializer(json_format) \
row_type_info = Types.ROW_NAMED(['name', 'age'], [Types.STRING(), Types.INT()])
json_format = JsonRowSerializationSchema.builder().with_type_info(row_type_info).build()

sink = KafkaSink.builder() \
    ) \