From bc4c70dde1c890caec486a4d893c3a0ac847c90c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Thu, 4 Feb 2021 10:17:54 +0100 Subject: [PATCH] Allow JsonbDeserializer based on generic types --- .../serialization/JsonbDeserializer.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/serialization/JsonbDeserializer.java b/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/serialization/JsonbDeserializer.java index 41d7d9ae93fa80..cff85c1860f207 100644 --- a/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/serialization/JsonbDeserializer.java +++ b/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/serialization/JsonbDeserializer.java @@ -3,6 +3,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Type; import java.util.Map; import javax.json.bind.Jsonb; @@ -15,18 +16,32 @@ public class JsonbDeserializer implements Deserializer { private final Jsonb jsonb; - private final Class type; + private final Type type; private final boolean jsonbNeedsClosing; - public JsonbDeserializer(Class type) { + public JsonbDeserializer(Class clazz) { + this(clazz, JsonbProducer.get(), true); + } + + public JsonbDeserializer(Class clazz, Jsonb jsonb) { + this(clazz, jsonb, false); + } + + private JsonbDeserializer(Class clazz, Jsonb jsonb, boolean jsonbNeedsClosing) { + this.type = clazz; + this.jsonb = jsonb; + this.jsonbNeedsClosing = jsonbNeedsClosing; + } + + public JsonbDeserializer(Type type) { this(type, JsonbProducer.get(), true); } - public JsonbDeserializer(Class type, Jsonb jsonb) { + public JsonbDeserializer(Type type, Jsonb jsonb) { this(type, jsonb, false); } - private JsonbDeserializer(Class type, Jsonb jsonb, boolean jsonbNeedsClosing) { + private JsonbDeserializer(Type type, Jsonb jsonb, boolean jsonbNeedsClosing) { this.type = type; this.jsonb = jsonb; this.jsonbNeedsClosing = jsonbNeedsClosing;