Replies: 2 comments 1 reply
-
|
Fory do have custimized serializer support, you can refer to https://fory.apache.org/docs/docs/guide/java_object_graph_guide#register-custom-serializers class Foo {
public long f1;
private void writeObject(ObjectOutputStream s) throws IOException {
System.out.println(f1);
s.defaultWriteObject();
}
}
class FooSerializer extends Serializer<Foo> {
public FooSerializer(Fory fory) {
super(fory, Foo.class);
}
@Override
public void write(MemoryBuffer buffer, Foo value) {
buffer.writeInt64(value.f1);
}
@Override
public Foo read(MemoryBuffer buffer) {
Foo foo = new Foo();
foo.f1 = buffer.readInt64();
return foo;
}
}
Fory fory = getFory();
fory.registerSerializer(Foo.class, new FooSerializer(fory)); |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
When you register serializer for an abstract classes, that serializer will be applied to all subclasses. But we do not have such support for non-abstract classes. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm experimenting writing a serialization module that can be used with Apache Pekko. Pekko's main serialization module is Jackson based. That Jackson based implementation has a few custom serializers/deserializers for some important classes.
I need to be able to serialize/deserialize a class that looks like
class Command(T payload, ActorRef ref)The existing ActorRef serializer/deserializer serializes an address value as a String instead trying to serialize all the state of the ActorRef.
Would it be possible to consider Fory support for registering custom serializer/deserializer combos for some classes and that these classes can be embedded in classes? In the Command class above, I would want to get Fory to serialize the full Command but when it gets to handling the ActorRef field that it uses the custom serializer that I have registered with Fory for the ActorRef class.
One idea would be on ForyBuilder to support
registerCustomSerialization<T, S>(Class<T> clazz, Function<T, S> serializeFn, Function<S, T> deserializeFn, boolean supportSubclasses)So when we run into an object instance in structured data that has a Class that matches T then we use the serializeFn to convert to class S, and on deserialization, we use the equivalent deserializeFn that converts from type T to type S.
If
supportSubclassesis set to true, T and any subclass of T is supported. Otherwise, the T check is an exact match.Beta Was this translation helpful? Give feedback.
All reactions