Skip to content

Commit

Permalink
Allow JsonbDeserializer based on generic types
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Feb 8, 2021
1 parent 8c7b1b5 commit bc4c70d
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,18 +16,32 @@
public class JsonbDeserializer<T> implements Deserializer<T> {

private final Jsonb jsonb;
private final Class<T> type;
private final Type type;
private final boolean jsonbNeedsClosing;

public JsonbDeserializer(Class<T> type) {
public JsonbDeserializer(Class<T> clazz) {
this(clazz, JsonbProducer.get(), true);
}

public JsonbDeserializer(Class<T> clazz, Jsonb jsonb) {
this(clazz, jsonb, false);
}

private JsonbDeserializer(Class<T> 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<T> type, Jsonb jsonb) {
public JsonbDeserializer(Type type, Jsonb jsonb) {
this(type, jsonb, false);
}

private JsonbDeserializer(Class<T> type, Jsonb jsonb, boolean jsonbNeedsClosing) {
private JsonbDeserializer(Type type, Jsonb jsonb, boolean jsonbNeedsClosing) {
this.type = type;
this.jsonb = jsonb;
this.jsonbNeedsClosing = jsonbNeedsClosing;
Expand Down

0 comments on commit bc4c70d

Please sign in to comment.