来自FasterXML的ReadValue时Flink收集器问题 [英] Flink Collector Issue While ReadValue from FasterXML
问题描述
我将Kafka值设置为String,并将POJO设置如下,
I have Kafka values as String, and POJO as below,
{"name":"John","timeStamp":"2020-08-11T13:31:31"}
class Person{
private String name;
private LocalDateTime timeStamp;
}
此时间戳记是来自Kafka的String,并将其转换为LocalDateTime
.
this Time Stamp comes as String from Kafka, and converting them into LocalDateTime
.
当我使用FasterXML的所需库以独立模式和objectMapper.readValue(value, Person.class)
身份运行程序时,它运行良好.正在转换.
When i run the program as Standalone and objectMapper.readValue(value, Person.class)
using required library from FasterXML, it works fine. It's converting.
当我从Flink Framework阅读以下内容时,
When I read from Flink Framework with the below,
stream.flatMap(new FlatMapFunction<String, Person>() {
public void flatMap(String value, Collector<Person> out) {
try {
out.collect(objectMapper.readValue(value, Person.class));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
}).print();
env.execute();
我遇到了以下问题,
Exception in thread "main" org.apache.flink.api.common.InvalidProgramException: com.fasterxml.jackson.databind.json.JsonMapper@1b7cc17c is not serializable. The object probably contains or references non serializable fields.
该消息显示我的Person对象不可序列化,并且我已经为Person
类实现了Serializable
,但是没有运气.而且,在下面尝试过,也不是很幸运.
The message shows me the Person object is not serializable, and i have implemented Serializable
for Person
class but no luck. And also, tried below, not luck too.
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime timeStamp;
更新:
类似于API的问题,我在下面的链接中阅读
Looks like issue with API, i read in the below link,
https://issues.apache.org/jira/browse/FLINK-12113
推荐答案
该异常指出JsonMapper
实例不是Serializable
-如果我没记错的话,它已从版本2.1
开始可序列化. .另外,Person
类也应设置为可序列化.
The exception states that the JsonMapper
instance is not Serializable
- if I'm not mistaken, it has been made serializable as of version 2.1
. Also, Person
class should be made serializable as well.
所以,在您的情况下,我会说您应该切换到jackson-databind
版本>=2.1
或可能将JsonMapper static
字段设置为
So, in your case I would say you should either switch to jackson-databind
version >=2.1
or probably make JsonMapper static
field.
对于Person
类,只需实现Serializable
接口:
In case of Person
class, just simply implement Serializable
interface:
class Person implements Serializable {
private String name;
private LocalDateTime timeStamp;
}
这篇关于来自FasterXML的ReadValue时Flink收集器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!