Skip to content

Support deserialization of generic types #293

Description

@xiazuojie

Describe the proposal

The following deserialize API asks for a Class<T>. It does not work with generic types.

<T> T deserialize(byte[] data, Class<T> clazz) throws IOException

Maybe add another method with the second param as java.lang.reflect.Type, which can accept both java.lang.Class and java.lang.reflect.ParameterizedType.

<T> T deserialize(byte[] data, java.lang.reflect.Type type) throws IOException

Jackson works with java.lang.reflect.Type as follows:

    public <T> T deserialize(byte[] data, java.lang.reflect.Type type) throws IOException {
        return objectMapper.readValue(data, objectMapper.constructType(type));
    }

Metadata

Metadata

Type

No type

Fields

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