Is there any safe way to serialize/deserialize Java Lambda for two different JREs?

510 Views Asked by At

There is a client that needs to serialize many lambda functions defined in the client side and send them to the server, which has to be able to correctly deserialize them.

The server also have implementations of all those lambda functions in the client, but the details could be slightly different from the client-side implementations (like minor versioning differences).

Given that Java Lambdas depends on compiler specific artifacts, simply serializing a lambda function to SerializedLambda and send it to the server side wouldn't work since the minor difference in the server side implementation could make itself incompatible to the serialized lambda expression.

My question here is, with a serialized lambda from the client, is there any way to invoke the corresponding lambda function on the server ? I have full controls over the serialization/deserialization in this case, but I do not have controls over the implementations of the lambda functions in both client/server. There can be thousands or tends of thousands of these lambda functions, which makes it difficult for me to define rules for each lambda function manually.

So, given (enclosing) class name, method types (arg types + return type), lambda function name, is it possible to invoke the corresponding implementation of lambda on the server side?


What can I do if lambdas are not from the fixed set? Is it impossible to have a single ser/deser rule to resolve this issue ?

0

There are 0 best solutions below