Skip to content

Support of TypeToken #165

@m0mus

Description

@m0mus

Extend deserialize family with a method accepting TypeToken. It's more convenient and user friendly than using pure Type. Similar mechanism is used in Gson and Jackson.

Deserialization of generic list as it is now:

// List of dogs
List<Dog> dogs = new ArrayList<>();

// Initialization
...

// Create Jsonb and deserialize
Jsonb jsonb = JsonbBuilder.create();
dogs = jsonb.fromJson(result, new ArrayList<Dog>(){}.getClass().getGenericSuperclass());

Deserialization of generic list using TypeToken:

// List of dogs
List<Dog> dogs = new ArrayList<>();

// Initialization
...

// Create Jsonb and deserialize
Jsonb jsonb = JsonbBuilder.create();
dogs = jsonb.fromJson(result, TypeToken<List<Dog>>(){}.getType());

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions