cartridge-java
cartridge-java copied to clipboard
Incorrect implementation of the map converter
Test case:
@Test
public void test(){
DefaultMessagePackMapper mapper = DefaultMessagePackMapperFactory.getInstance().defaultComplexTypesMapper();
Map<Long, String> expected = new HashMap<>();
expected.put((long) (Short.MAX_VALUE + 1), "test");
expected.put((long) (Short.MAX_VALUE + 2), "test");
Map<Long, String> actual = mapper.fromValue(mapper.toValue(expected));
String s = expected.get((long) Short.MAX_VALUE + 1);
String t = actual.get((long) Short.MAX_VALUE + 1);
assertNotNull(s);
assertNotNull(t); //fail at this assertion!!!
}
This case shows that when a value in the range of Integer
is inserted into the map, the Integer
converter is taken from the converter stack, regardless of the specified generic class in the resulting variable.
(The same thing happens with short
and int
, respectively)
This problem can be solved by rewriting the DefaultMapObjectConverter
, specifically the toValue
method. Perhaps through reflection.