RuedigerMoeller / fast-serialization

FST: fast java serialization drop in-replacement
Apache License 2.0
1.58k stars 248 forks source link

Force Serialization of Lambdas #320

Open magicwerk opened 2 years ago

magicwerk commented 2 years ago

I try to use FST to serialize Java objects where not all contained instances are Serializable by using

FSTConfiguration.getDefaultConfiguration().setForceSerializable(true)

However this does not seem to work for classes containing lambdas: java.lang.ClassNotFoundException: eval.fst.EvalFst$NoSerializableLambda$$Lambda$3/205962452

class NoSerializableLambda { Predicate filter = (s) -> s.startsWith("a"); }

Is there a way to configure FST so also lambdas can be serialized?

masmc05 commented 2 years ago

try Predicate<String> filter = (Predicate<String> & Serializable) (s) -> s.startsWith("a"); this will make the lambda serializable idk if there are other solutions

magicwerk commented 2 years ago

I'm aware of how lambdas can be made explicitly Serializable as shown, thanks. The interesting part however would be whether FST somehow manages to serialize lambdas not defined as Serializable, as it manages to serialize classes not implementing Serialiazable.