diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/Factory.java b/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/Factory.java deleted file mode 100644 index 91b4843e..00000000 --- a/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/Factory.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.jayway.jsonpath.spi.mapper; - -public interface Factory { - - T createInstance(); -} diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/GsonMappingProvider.java b/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/GsonMappingProvider.java index 7bf3a9db..7e5153b4 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/GsonMappingProvider.java +++ b/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/GsonMappingProvider.java @@ -23,22 +23,24 @@ import com.jayway.jsonpath.TypeRef; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.concurrent.Callable; + public class GsonMappingProvider implements MappingProvider { private static final Logger logger = LoggerFactory.getLogger(GsonMappingProvider.class); - private final Factory factory; + private final Callable factory; public GsonMappingProvider(final Gson gson) { - this(new Factory() { + this(new Callable() { @Override - public Gson createInstance() { + public Gson call() { return gson; } }); } - public GsonMappingProvider(Factory factory) { + public GsonMappingProvider(Callable factory) { this.factory = factory; } @@ -46,9 +48,9 @@ public class GsonMappingProvider implements MappingProvider { super(); try { Class.forName("com.google.gson.Gson"); - this.factory = new Factory() { + this.factory = new Callable() { @Override - public Gson createInstance() { + public Gson call() { return new Gson(); } }; @@ -61,7 +63,7 @@ public class GsonMappingProvider implements MappingProvider { @Override public T map(Object source, Class targetType, Configuration configuration) { try { - return factory.createInstance().getAdapter(targetType).fromJsonTree((JsonElement) source); + return factory.call().getAdapter(targetType).fromJsonTree((JsonElement) source); } catch (Exception e){ throw new MappingException(e); } @@ -70,7 +72,7 @@ public class GsonMappingProvider implements MappingProvider { @Override public T map(Object source, TypeRef targetType, Configuration configuration) { try { - return (T) factory.createInstance().getAdapter(TypeToken.get(targetType.getType())).fromJsonTree((JsonElement) source); + return (T) factory.call().getAdapter(TypeToken.get(targetType.getType())).fromJsonTree((JsonElement) source); } catch (Exception e){ throw new MappingException(e); } diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JsonSmartMappingProvider.java b/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JsonSmartMappingProvider.java index a3b072b4..f4f58cdc 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JsonSmartMappingProvider.java +++ b/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JsonSmartMappingProvider.java @@ -26,6 +26,7 @@ import java.math.BigDecimal; import java.text.DateFormat; import java.text.ParseException; import java.util.Date; +import java.util.concurrent.Callable; public class JsonSmartMappingProvider implements MappingProvider { @@ -48,18 +49,18 @@ public class JsonSmartMappingProvider implements MappingProvider { } - private final Factory factory; + private final Callable factory; public JsonSmartMappingProvider(final JsonReader jsonReader) { - this(new Factory() { + this(new Callable() { @Override - public JsonReader createInstance() { + public JsonReader call() { return jsonReader; } }); } - public JsonSmartMappingProvider(Factory factory) { + public JsonSmartMappingProvider(Callable factory) { this.factory = factory; } @@ -79,7 +80,7 @@ public class JsonSmartMappingProvider implements MappingProvider { } try { if(!configuration.jsonProvider().isMap(source) && !configuration.jsonProvider().isArray(source)){ - return factory.createInstance().getMapper(targetType).convert(source); + return factory.call().getMapper(targetType).convert(source); } String s = configuration.jsonProvider().toJson(source); return (T) JSONValue.parse(s, targetType);