简体   繁体   中英

Serialization of java.util.map and custom pojo in Flink

I am trying to use a pojo which does not implement Serializable from an external library in the kinesis flink application .The serialization is failing while using it inside flatMap function.

Pojo

public class ExecutionRecord {
    private Map<String, VariableGroup> factMap;
    private List<ModelResult> models;
    private List<RulesetResult> rulesets;
    private Outcome outcome;
    private ExecutionMetadata executionMetadata;
}

Output of TypeInformation.of(ExecutionRecord.class).toString()

PojoType<ExecutionRecord, fields = [executionMetadata: PojoType<ExecutionMetadata, fields = [endTime: String, evaluationType: String, executionHost: String, executionId: String, gmraInstanceIDs: GenericType<java.util.List>, startTime: String]>, factMap: GenericType<java.util.Map>, models: GenericType<java.util.List>, outcome: PojoType<Outcome, fields = [actions: GenericType<java.util.List>, failedActions: GenericType<java.util.List>, outcomeName: String]>, rulesets: GenericType<java.util.List>]>

Error- java.io.NotSerializableException: ExecutionRecord

The stack trace is also not showing which specific field it is not able to serialize.

How shall I register the serializer for java.util.list and java.util.map which are recognised as generic types and for rest of custom pojos

You can do something like this

public static final TypeInformation<ExecutionRecord> TYPE_INFORMATION_POJO = Types.POJO(ExecutionRecord.class);

or

public static final TypeInformation<ExecutionRecord> TYPE_INFORMATION = TypeInformation.of(BehProdViewFLDTO.class);

and pass either TYPE_INFORMATION_POJO or TYPE_INFORMATION to the states or when you may needed!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM