From 8ad622e6dbceae261f4b976138260aa5e8025c8a Mon Sep 17 00:00:00 2001 From: Dmitry Vasilenko Date: Wed, 17 Apr 2013 16:13:05 -0500 Subject: [PATCH] Updated JsonProviderFactory to set up default provider. --- .../jsonpath/spi/JsonProviderFactory.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/spi/JsonProviderFactory.java b/json-path/src/main/java/com/jayway/jsonpath/spi/JsonProviderFactory.java index 8f813181..39d371d9 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/spi/JsonProviderFactory.java +++ b/json-path/src/main/java/com/jayway/jsonpath/spi/JsonProviderFactory.java @@ -21,10 +21,23 @@ import com.jayway.jsonpath.spi.impl.JsonSmartJsonProvider; */ public abstract class JsonProviderFactory { + private static Class defaultProvider = null; + public static JsonProviderFactory factory = new JsonProviderFactory() { @Override protected JsonProvider create() { - return new JsonSmartJsonProvider(); + JsonProvider provider = null; + try { + if(defaultProvider != null) { + provider = (JsonProvider)defaultProvider.newInstance(); + } + } catch(Throwable t) { + + } + if(provider == null) { + provider = new JsonSmartJsonProvider(); + } + return provider; //return new JacksonProvider(); } }; @@ -33,6 +46,9 @@ public abstract class JsonProviderFactory { return factory.create(); } + public static synchronized void setDefaultProvider(Class jsonProvider) { + defaultProvider = jsonProvider; + } protected abstract JsonProvider create();