Skip to content

Java - how to handle generic types #2

@adicioban

Description

@adicioban

Hi,

I'm using RPC with a type that uses generic types.

The RPC method looks something like:

public Result doCommand(Command command) {

the Command class is as follows:

public class Command<D extends Data> extends SomethingSuper {
    private String id;
//more fields here
    private D data;

When creating the server I register the types that are being used and register command as such:

MessagePack msgPack = new MessagePack();
msgPack.register(ImplementationForD.class);
msgPack.register(Command.class);

and this conveniently creates a template object that handles correctly all the fields except for generic types D. I also register the implementations for types D.

When it comes to de-serialization msgpack picks up the field data as of type D for which it doesn't have any template that could be applied to read the value.

Please advise on how to solve this - if at all possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions