fast-serialization icon indicating copy to clipboard operation
fast-serialization copied to clipboard

Need support for handling cross services serialization and de-serialization with different package names

Open kaushalaroraharman opened this issue 10 months ago • 1 comments

Hello,

We are using FST library version 2.57 at HARMAN in production environment, and have run into a issue related to migration of the classes, post which deserialization is failing with FST.

Use Case:

  1. A event POJO class, named com.harman.ignite.EventA resides in a common library.
  2. ServiceA serializes com.harman.ignite.EventA using FST's writeObject() to convert it to byte[]
  3. This event is pushed to Kafka
  4. ServiceB consumes from Kafka, and de-serializes the byte[], back into com.harman.ignite.EventA, using FST's readObject().

This use was working fine.

What has changed? We have moved the class EventA to a different package i.e., org.eclipse.ecsp.EventA, with the same structure, only package has been changed. However, this change is reflected only for ServiceB, since ServiceA and ServiceB are using different versions of the common library which has EventA defined.

Updated Use Case:

  1. ServiceA serializes com.harman.ignite.EventA using FST's writeObject() to convert it to byte[]
  2. This event is pushed to Kafka
  3. ServiceB consumes from Kafka, and tries to de-serializes the byte[], back into org.eclipse.ecsp.EventA, using FST's readObject().

Since ServiceA is using com.harman.ignite.EventA to serialize, and ServiceB needs to use org.eclipse.ecsp.EventA to de-seriailize, currently, de-serialization is failing with "class not found CLASSNAME:com.harman.ignite.EventA".

Question: Is there any way to handle this scenario with FST wherein the serialization and de-serialization needs to be handled by different fully qualified class name with same structure?

I tried writing a custom class loader to map "com.harman.ignite", to "org.eclipse.ecsp" during deserialization, but that did not help in resolving this issue. Below is reference for the same -

conf.setClassLoader(new ClassLoader() {
            @Override
            public Class<?> loadClass(String name) throws ClassNotFoundException {
                String newName = name.replace("com.harman.ignite.EventA", "org.eclipse.ecsp.EventA");
                return Thread.currentThread().getContextClassLoader().loadClass(newName);
            }
        });

kaushalaroraharman avatar Jun 04 '25 08:06 kaushalaroraharman

Any inputs here?

kaushalaroraharman avatar Jun 09 '25 07:06 kaushalaroraharman