Long serialization fixed

pull/10/head
Nikita 11 years ago
parent 6a51679d7f
commit 37bd46561a

@ -21,6 +21,7 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTypeResolverBuilder; import com.fasterxml.jackson.databind.ObjectMapper.DefaultTypeResolverBuilder;
@ -49,7 +50,32 @@ public class JsonJacksonCodec implements RedissonCodec {
objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
// type info inclusion // type info inclusion
TypeResolverBuilder<?> typer = new DefaultTypeResolverBuilder(DefaultTyping.NON_FINAL); TypeResolverBuilder<?> typer = new DefaultTypeResolverBuilder(DefaultTyping.NON_FINAL) {
public boolean useForType(JavaType t)
{
switch (_appliesFor) {
case NON_CONCRETE_AND_ARRAYS:
while (t.isArrayType()) {
t = t.getContentType();
}
// fall through
case OBJECT_AND_NON_CONCRETE:
return (t.getRawClass() == Object.class) || !t.isConcrete();
case NON_FINAL:
while (t.isArrayType()) {
t = t.getContentType();
}
// to fix problem with wrong long to int conversion
if (t.isPrimitive() || t.getRawClass() == Long.class) {
return true;
}
return !t.isFinal(); // includes Object.class
default:
//case JAVA_LANG_OBJECT:
return (t.getRawClass() == Object.class);
}
}
};
typer.init(JsonTypeInfo.Id.CLASS, null); typer.init(JsonTypeInfo.Id.CLASS, null);
typer.inclusion(JsonTypeInfo.As.PROPERTY); typer.inclusion(JsonTypeInfo.As.PROPERTY);
objectMapper.setDefaultTyping(typer); objectMapper.setDefaultTyping(typer);

@ -111,6 +111,40 @@ public class RedissonMapTest extends BaseTest {
} }
@Test
public void testInteger() {
Redisson redisson = Redisson.create();
Map<Integer, Integer> map = redisson.getMap("test_int");
map.put(1, 2);
map.put(3, 4);
Assert.assertEquals(2, map.size());
Integer val = map.get(1);
Assert.assertEquals(2, val.intValue());
Integer val2 = map.get(3);
Assert.assertEquals(4, val2.intValue());
clear(map, redisson);
}
@Test
public void testLong() {
Redisson redisson = Redisson.create();
Map<Long, Long> map = redisson.getMap("test_long");
map.put(1L, 2L);
map.put(3L, 4L);
Assert.assertEquals(2, map.size());
Long val = map.get(1L);
Assert.assertEquals(2L, val.longValue());
Long val2 = map.get(3L);
Assert.assertEquals(4L, val2.longValue());
clear(map, redisson);
}
@Test @Test
public void testNull() { public void testNull() {
Redisson redisson = Redisson.create(); Redisson redisson = Redisson.create();

Loading…
Cancel
Save