Skip to content

[Java] auto generic cast for fury deserialization #982

@chaokunyang

Description

@chaokunyang

Is your feature request related to a problem? Please describe.

Currently fury deserialize method return Object type, if users serialized an object of type Foo, users needs to cast to Foo manually:

byte[] d = fury.serialize(foo);
Object o = fury.deserialize(d);
Foo o1 = (Foo) o;

This is inconvenient, and if there are generics such as:

Foo<A> foo = xxx;
byte[] d = fury.serialize(foo);
Object o = fury.deserialize(d);
Foo<A> foo o1 = (Foo<A> foo) o;

the cast will issue a javac warnings.

Then users will need to warp an util like this:

@SuppressWarnings("unchecked")
public static <T> T deserialize(byte[] b) {
  Object o = fury.deserialize(b);
  return (T) o;
}

We should do this for users.

Describe the solution you'd like

Implement cast in fuyr:

@SuppressWarnings("unchecked")
public static <T> T deserialize(byte[] b) {
  Object o = fury.deserialize(b);
  return (T) o;
}

Note if users declare error type, the deserialization will raise ClassCastException:

Foo<A> foo = xxx;
byte[] d = fury.serialize(foo);
Bar o = fury.deserialize(d); // raise ClassCastException.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions