3535import java .util .stream .Stream ;
3636
3737import com .google .gson .Gson ;
38+ import com .google .gson .GsonBuilder ;
3839
3940import redis .clients .jedis .Jedis ;
4041import redis .clients .jedis .JedisPool ;
4849 */
4950public class JReJSON {
5051
51- private static final Gson gson = new Gson ();
52+ private GsonBuilder gsonBuilder = new GsonBuilder ();
53+ private Gson gson = gsonBuilder .create ();
54+
55+ public void setGsonBuilder (GsonBuilder gsonBuilder ) {
56+ this .gsonBuilder = gsonBuilder ;
57+ this .gson = gsonBuilder .create ();
58+ }
5259
5360 private enum Command implements ProtocolCommand {
5461 DEL ("JSON.DEL" ),
@@ -100,6 +107,7 @@ public byte[] getRaw() {
100107 }
101108
102109 private Pool <Jedis > client ;
110+ private Jedis jedis ;
103111
104112 /**
105113 * Creates a client to the local machine
@@ -127,6 +135,10 @@ public JReJSON(Pool<Jedis> jedis) {
127135 this .client = jedis ;
128136 }
129137
138+ public JReJSON (Jedis jedis ) {
139+ this .jedis = jedis ;
140+ }
141+
130142 /**
131143 * Helper to check for an OK reply
132144 * @param str the reply string to "scrutinize"
@@ -389,6 +401,8 @@ public Class<?> type(String key, Path path) {
389401 }
390402 }
391403
404+ private static final Gson staticGson = new Gson ();
405+
392406 /**
393407 * Deletes a path
394408 * @param conn the Jedis connection
@@ -436,7 +450,7 @@ public static Object get(Jedis conn, String key, Path... paths) {
436450 String rep = conn .getClient ().getBulkReply ();
437451 conn .close ();
438452
439- return gson .fromJson (rep , Object .class );
453+ return staticGson .fromJson (rep , Object .class );
440454 }
441455
442456 /**
@@ -455,7 +469,7 @@ public static void set(Jedis conn, String key, Object object, ExistenceModifier
455469
456470 args .add (SafeEncoder .encode (key ));
457471 args .add (SafeEncoder .encode (getSingleOptionalPath (path ).toString ()));
458- args .add (SafeEncoder .encode (gson .toJson (object )));
472+ args .add (SafeEncoder .encode (staticGson .toJson (object )));
459473 if (ExistenceModifier .DEFAULT != flag ) {
460474 args .add (flag .getRaw ());
461475 }
@@ -523,7 +537,7 @@ public static Class<?> type(Jedis conn, String key, Path... path) {
523537 }
524538
525539 private Jedis getConnection () {
526- return this .client .getResource ();
540+ return jedis != null ? jedis : this .client .getResource ();
527541 }
528542
529543 /**
0 commit comments