Skip to content

How can I get generics info inside custom deserializer? #4274

Closed Answered by yvasyliev
yvasyliev asked this question in Q&A
Discussion options

You must be logged in to vote

After some research I found a solution that works for me. Here's my updated WrappedListDeserializer:

public class WrappedListDeserializer<T extends Wrappable> extends JsonDeserializer<List<T>> implements ContextualDeserializer {
    private JavaType type;

    @Override
    public List<T> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        return ctxt.readValue(p, type);
    }


    @Override
    public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) {
        WrappedListDeserializer<T> deserializer = new WrappedListDeserializer<>();
        deserializer.type = property.getType();
        return deserializer;
    }
}

A…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@yvasyliev
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by yvasyliev
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants