Skip to content

Commit d83ab24

Browse files
authored
Redis Exception: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class java.util.Vector (#575)
* try fix redis serialization error * no message * try fix redis serialization error * try fix redis serialization error * Restore original cache value * Restore original cache value * Remove unused import
1 parent 051478a commit d83ab24

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

java/src/main/java/com/genexus/cache/redis/RedisClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import java.util.ArrayList;
88
import java.util.List;
99

10+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
1011
import org.apache.commons.lang.StringUtils;
1112

12-
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
1313
import com.fasterxml.jackson.annotation.PropertyAccessor;
1414
import com.fasterxml.jackson.databind.DeserializationFeature;
1515
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -79,7 +79,11 @@ private void initCache(String hostOrRedisURL, String password, String cacheKeyPa
7979
pool = new JedisPool(new JedisPoolConfig(), host, port, redis.clients.jedis.Protocol.DEFAULT_TIMEOUT, password);
8080

8181
objMapper = new ObjectMapper();
82-
objMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
82+
objMapper
83+
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
84+
.setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.NONE)
85+
.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.NONE)
86+
.setVisibility(PropertyAccessor.CREATOR, JsonAutoDetect.Visibility.NONE);
8387
objMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
8488
objMapper.enable(SerializationFeature.INDENT_OUTPUT);
8589
}

java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.genexus.cache.redis;
22

3+
import com.genexus.db.CacheValue;
34
import org.apache.logging.log4j.LogManager;
45
import org.apache.logging.log4j.Logger;
56
import com.genexus.specific.java.Connect;
@@ -10,6 +11,7 @@
1011
import redis.clients.jedis.JedisPool;
1112

1213
import java.net.URISyntaxException;
14+
import java.util.concurrent.ThreadLocalRandom;
1315

1416
import static org.junit.Assume.assumeTrue;
1517

@@ -95,16 +97,30 @@ public void testSetRedis()
9597
Assert.assertNotNull("Redis instance could not be created", redis);
9698

9799
String cacheId = "TEST";
98-
String cacheKey = "TEST_KEY";
100+
String cacheKey = "TEST_KEY" + ThreadLocalRandom.current().nextInt();
99101
String cacheValue = "KeyValue";
100102
redis.set(cacheId, cacheKey, cacheValue);
101103

102104
String obtainedValue = redis.get(cacheId, cacheKey, String.class);
103-
104105
Assert.assertEquals(obtainedValue, cacheValue);
106+
}
105107

108+
@Test
109+
public void testSetCacheValueRedis()
110+
{
111+
Connect.init();
106112

113+
RedisClient redis = getRedisClient("", "");
114+
Assert.assertNotNull("Redis instance could not be created", redis);
107115

116+
String cacheId = "TEST"+ ThreadLocalRandom.current().nextInt();
117+
String cacheKey = "TEST_KEY" + ThreadLocalRandom.current().nextInt();
118+
CacheValue c = new CacheValue("SELECT * FROM User;", new Object[] { 1, 2, 3});
119+
c.addItem(123);
120+
redis.set(cacheId, cacheKey, c);
121+
CacheValue obtainedValue = redis.get(cacheId, cacheKey, CacheValue.class);
122+
Assert.assertNotNull(obtainedValue);
108123
}
109124

125+
110126
}

0 commit comments

Comments
 (0)